Lets suppose that there are two binary files, e.g. XXX
and YYY
, at destination /usr/bin/
. I want to start them at once, always! In other words, when I type the name of either of those in unity, I want to make both of them start. How could I change the corresponding files at destination /home/username/.local/applications/
to do so? I tried this /usr/bin/XXX;/usr/bin/YYY;
on terminal but it doesn't seem to work.
-
1There are TWO aspects to this question. One of them is running TWO apps apparently simultaneously. The other is making both run when the command name of just one (either) of them is typed into.– SkaperenFeb 27, 2013 at 14:04
4 Answers
As I understand you need to edit your .desktop
file. Add this line next to Exec
:
sh -c "/usr/bin/XXX & /usr/bin/YYY"
The -c
flag tells to the shell that it has to read the commands from string, instead of from the standard input.
If you use only /usr/bin/XXX & /usr/bin/YYY
it won't work. Just to add the reason why &
doesn't work in a launcher, it's because &
is a feature of the shell, and the launcher isn't a shell, its a much simpler environment for running commands.
-
3Thanks, in fact, based on the answers bellow, I used a singe & instead. Therefore, the solution that worked for me is:
sh -c "/usr/bin/XXX & /usr/bin/YYY;"
Feb 27, 2013 at 10:59 -
2in this case, it should be
&
, not&&
- the latter waits for the first command to finish, and then only runs the seccond if the first was successful.&
starts the first one and then starts the second straight away. Feb 27, 2013 at 13:18 -
1
/usr/bin/app_first &
/usr/bin/app_second
Using '&' you are sending process into background.
-
-
@Private but it starts the second at the same time, which is what OP asked for Feb 27, 2013 at 13:19
You should use
/usr/bin/XXX && /usr/bin/YYY;
Note the use of &&
(no need to use &
to run something in the background).
-
3This is not exactly true. If the XXX is not detaching by itself - the YYY is not run as long XXX will be dead - so you are not gonna run two apps at once.– bluszczFeb 27, 2013 at 10:25
-
@bluszcz && doesn't work in my case. Plus, I notice some differences on terminal’s output when XXX is called first compared to the case where YYY is called first. What's the reason for that? Feb 27, 2013 at 10:29
-
And saying more, 'YYY' will work if 'XXX' finished it lifetime with success. If 'XXX' fails - you will never get YYY running.– bluszczFeb 27, 2013 at 10:29
-
-
1It seems that putting process to background worked out for him - and this is why I understood that question.– bluszczFeb 27, 2013 at 10:33
You will need to add the command names XXX and YYY into a directory at an earlier point in the search path. For both this command named file will run the original XXX and YYY by using the full path names /usr/bin/XXX and /usr/bin/YYY. This is to prevent the script from re-running itself forever in a loop (or until your computer runs out of memory). An alternative to this is replacing the commands with your script and moving the original commands to another path like /usr/local/bin.
This script needs to run both /usr/bin/XXX and /usr/bin/YYY in the background so they are running at the same time. The classic way to do this is:
/usr/bin/XXX &
/usr/bin/YYY
As described by bluszcz above. You might also want to put the " &" on the 2nd command as well. An alternative way to more quietly put these commands in the background is with screen, which could be coded in the script like this:
screen -dmS XXX /usr/bin/XXX
screen -dmS YYY /usr/bin/YYY
That can have the advantage in cases where you might want to go see the progress of the commands without doing logging, bu using screen to attach to the sessions that creates.