Reputation: 199
How to pass command line argument to a script which should be run in the background? I tried the below command and it gives an error:
system("perl sample.pl& 1");
Error: 1: command not found
Upvotes: 0
Views: 190
Reputation: 790
The reason that does not work is due to the all arguments must be before the ampersand
So system("perl sample.pl 1 &");
Alternatively you can use exec() or backticks. For example `perl sample.pl 1 &`
If you use exec though, just know it never returns where system does.
Upvotes: 0
Reputation: 27528
Arguments to the program being run in the background have to be placed before the ampersand:
perl sample.pl 1 &
What you typed is recognized by the shell (I'm assuming you're on a Unix or Linux variant) as 2 separate commands:
perl sample.pl
which is run in the background, and
1
Where the shell is reporting that 1 is not a valid command.
Upvotes: 3