2

If I enter lxterminal in a terminal window, a new terminal window pops up and it stays there. But if I enter lxterminal -e "dir", the window just flashes and disappears. How can I set it to stay there?

This part of a bigger task where I am trying to get a python script to run in a terminal window automatically on start up, but until I can get the terminal window to come up and stay there I am stuck.

0

In a script, to open a new window, use this line:

lxterminal &

and type ls

The pound sign will keep the window open.

This will work for sure.

If you are on Ubuntu, substitute gnome-terminal for lxwindow, by the way.

You have already figured out how to do this one from the command line, but in a script you want the ampersand if it is to open a new window and keep it open.

-----------------------------------------------------------------------

For your long-term project, you will find that you will have no trouble with using

lxterminal -e myproject &

as long as myproject has a shebang as the first line (use the return from which python in the shebang). This minimal example assumed myproject is in the current directory or is in the path like in /usr/sbin

The ampersand (&) will keep it open in a separate window.

Look below at my script and you can see that I use a variation to simply open gnuplot. Your myproject will work the same way

Note that if you want to display a directory in python you can use the os library. You can even use os.system("lxterminal") to open a new terminal from within your program.

I also see in StackOverflow there is some discussion about popen and checkprocess for problems like this in Python. Seems the same happens with the ps command, when called from within Python.

https://stackoverflow.com/questions/3791465/python-os-system-for-command-line-call-linux-not-returning-what-it-should

Here's one portion that you might find interesting

If you're only interested in the output from the process, it's easiest to use subprocess' check_output function:


output = subprocess.check_output(["command", "arg1", "arg2"]);

Then output holds the program output to stdout. Check the link above for more info.

-----------------------------------------------------------------------

Background on why I believe this is your answer:

I use a script that does this:

cd ~/python
lxterminal &
lxterminal -e gnuplot &

and it opens two terminal windows: One sitting at a prompt, and one sitting at the gnuplot prompt, with both in the correct directory. It leaves the original terminal open also.

Then I work for hours using those two windows. editors and scripts for data manipulation in the command window, then plotting in the gnuplot window. (I use the reread statement in some plots so the plot window updates periodically as I change the underlying data.)

----------------------------------------------------------------

You threw a real curveball with your question text, by the way. I gave it the old college try to answer it specifically.

I tried a bunch of different methods to make it show a directory before the prompt, including calling a script that does the ls and then a pause, and ls simply hangs up. Also tried doing ls >ls.tmp then cat ls.tmp in a script, and even ls | more and every way I tried to get it to do what you are asking failed because there is something different about ls. Whether in a separate script, or using -e "ls; pause" it simply hangs.

Hence the solution above that is closest to what you are asking for.

Long-term prognosis for your project is good.

I believe the most important thing you were seeking was the ampersand to hold the window open when invoked in a script.

  • didn't work for me :( – DarkCygnus Aug 16 '18 at 22:15
0

I have a program that runs at start up in a terminal window with no issues.

This is what I have done.

  1. Go to directory home/pi/

  2. Right click empty space and click 'show hidden folders'

  3. Open file: home/pi/.config/lxsession/LXDE-pi/autostart

  4. Add the following line to the bottom:

    @lxterminal -e python3 /file/path/here.py

  5. Save and exit file.

  6. Reboot controller. Terminal should open and automatically start Program.

EDIT: This is assuming you are using a python program. Obviously will have to be edited a little, otherwise

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.