LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-08-2016, 08:56 AM   #1
P.G.Krish
Member
 
Registered: Jun 2016
Distribution: Ubuntu
Posts: 64

Rep: Reputation: Disabled
Lightbulb 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
 
Old 06-08-2016, 09:20 AM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
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
 
1 members found this post helpful.
Old 06-08-2016, 10:57 AM   #3
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Quote:
Originally Posted by P.G.Krish View Post
Iam using ubuntu

I want to run my node app in background and curl simultaneously
Just do
Code:
node app.js & ; curl localhost &
 
1 members found this post helpful.
Old 06-08-2016, 11:13 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
My question would be why you thought you needed &&?
 
Old 06-09-2016, 04:21 AM   #5
P.G.Krish
Member
 
Registered: Jun 2016
Distribution: Ubuntu
Posts: 64

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by keefaz View Post
Just do
Code:
node app.js & ; curl localhost &
This command says
Code:
bash: syntax error near unexpected token `;'
 
Old 06-09-2016, 04:23 AM   #6
P.G.Krish
Member
 
Registered: Jun 2016
Distribution: Ubuntu
Posts: 64

Original Poster
Rep: Reputation: Disabled
Red face

Quote:
Originally Posted by grail View Post
My question would be why you thought you needed &&?
I thought because it will run two commands frequently
 
Old 06-09-2016, 06:22 AM   #7
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Quote:
Originally Posted by P.G.Krish View Post
This command says
Code:
bash: syntax error near unexpected token `;'
Oops, you don't need semicolon there
Code:
node app.js & curl localhost &
 
1 members found this post helpful.
  


Reply

Tags
shell, terminal



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How does '&' make a process run in background ? Aquarius_Girl Programming 22 12-22-2009 10:58 AM
Bash background (&) with control operators (&&) int0x80 Programming 1 02-11-2009 12:54 PM
running a program in background of X using & Dachy Linux - General 1 09-13-2005 11:38 AM
Phục hồi dữ liệu bị mất???, cứ pollsite General 1 06-27-2005 12:39 PM
is there a way to traverse a directory structure & execute a command hemlock Linux - Newbie 1 09-07-2002 12:22 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration