简体   繁体   中英

Linux equivalent of the DOS "start" command?

我正在编写 ksh 脚本,并且必须在单独的命令提示符窗口中运行可执行文件。

xdg-open is a similar command line app in linux.

see https://superuser.com/questions/38984/linux-equivalent-command-for-open-command-on-mac-windows for details on its use.

I believe you mean something like xterm -e your.sh &

Don't forget the final &

maybe it´s not a seperate window that gets started, but you can run some executables in background using "&"

eg

./myexecutable &

means your script will not wait until myexecutable has finished but goes on immediately. maybe this is what you are looking for. regards

xdg-open is a good equivalent for the MS windows commandline start command: xdg-open file opens that file or url with its default application xdg-open . opens the currect folder in the default file manager

One of the most useful terminal session programs is screen.

screen -dmS title executable

You can list all your screen sessions by running

screen -ls

And you can connect to your created screen session (also allowing multiple simultaneous/synchronized sessions) by running

screen -x title

This will open up the emulated terminal in the current window where executable is running. You can detach a screen session by pressing Ca Cd, and can reattach as many times as you wish.

If you really want your program started in a new terminal window, you could do something like this: xterm yourtextmodeprogram or gnome-terminal -e yourtextmodeprogram or konsole -e mc

Trouble is that you cannot count on a particular terminal emulator being installed, so (again: if you really want to do this) you would need to look for the common ones and then execute the first one encountered.

As Joachim mentioned: The normal way to do this is to background the command (read about shell job control somewhere, if you want to dig deeper).

There are also cases where you want to start a persistent shell, ie a shell session which lives on when you close the terminal window. There are two ways to do this:

  • batch-oriented: nohup command-to-run &
  • interactive: screen

if you want a new windows, just start a new instance of your terminal application: in kde it's

konsole -e whatever

i'm sure the Gnome terminal has similar options

Some have recommended starting it in the background with &, but beware that that will still send all console output from the application you launch to the terminal you launched it from. Additionally, if you close the initial terminal the program you loaded will end.

If you're using a desktop environment like KDE or GNOME, I'd check the alt+f2 launching apps (gnome-open is the one for GNOME, I don't know the name of the KDE app) and see if you can pass them the command to launch as an argument.

Also, if your intention is to launch a daemon, you should check the nohup documentation.

I used nohup as the following command and it works:

nohup <your command> &

then press enter and enter! don't forget the last &

for example, I ran a python code listening to port 5000: nohup python3 -W ignore mycode.py & then I made sure of running by netstat -tulnp | grep :5000netstat -tulnp | grep :5000 and it was ok.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM