LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to run a program in background and also using && to execute another command (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-run-a-program-in-background-and-also-using-and-and-to-execute-another-command-4175581751/)

P.G.Krish 06-08-2016 08:56 AM

How to run a program in background and also using && to execute another command
 
Iam using ubuntu

I want to run my node app in background and curl simultaneously using && .I tried following but not work

Code:

node app.js &;curl localhost
and i tried another one

Code:

node app.js & && curl localhost
but both not working

Guttorm 06-08-2016 09:20 AM

Hello

Using both & and && doesn't really make sense. The && means only start the second command if the first doesn't fail. And & means run the first command in the background - execute the second without waiting for the first command to finish. If the second should start anyway, you could do something like this:

Code:

(node app.js &) ; curl localhost
If the second command fails because app.js hasn't started yet, you could maybe add some sleep so it has time to start?

Code:

(node app.js &) ; sleep 3 ; curl localhost

keefaz 06-08-2016 10:57 AM

Quote:

Originally Posted by P.G.Krish (Post 5557725)
Iam using ubuntu

I want to run my node app in background and curl simultaneously

Just do
Code:

node app.js & ; curl localhost &

grail 06-08-2016 11:13 AM

My question would be why you thought you needed &&?

P.G.Krish 06-09-2016 04:21 AM

Quote:

Originally Posted by keefaz (Post 5557792)
Just do
Code:

node app.js & ; curl localhost &

This command says
Code:

bash: syntax error near unexpected token `;'

P.G.Krish 06-09-2016 04:23 AM

Quote:

Originally Posted by grail (Post 5557800)
My question would be why you thought you needed &&?

I thought because it will run two commands frequently

keefaz 06-09-2016 06:22 AM

Quote:

Originally Posted by P.G.Krish (Post 5558254)
This command says
Code:

bash: syntax error near unexpected token `;'

Oops, you don't need semicolon there
Code:

node app.js & curl localhost &


All times are GMT -5. The time now is 07:39 PM.