3
votes

So in my script I need to make to calls to unix, and I do it via the system command like so:

system "bash -i -c 'addmothernode'";

...

perl code ...

...

system "bash -i -c 'addnode -ip=$_'";

However, whenever I run both of these commands in the same script, for some reason my process is stopped like this:

[1]+  Stopped                 perl boot.pl

And the script can only be finished when I run fg %1. When I only have one of these system calls in, the perl script finishes successfully. But I need both commands because they depend on each other. Anyone have any ideas about what's going on? Thanks!

UPDATE:

A lot of answers below are saying I don't need to use bash -i to run a system command, and I know typically this is true but I need to use aliases that I have created and if I do not use this the aliases won't be recognized. So I do need bash -i.

3

3 Answers

4
votes

This problem is unrelated to perl. You can easily reproduce the situation if you start two bashes in the interactive mode (-i) one after another:

$ cat 1.sh 
bash -i -c 'sleep 1'
bash -i -c 'sleep 1'

$ bash 1.sh

[1]+  Stopped                 bash 1.sh

Of course it would be better to run bash in the non-interactive mode (without -i) or run the program directly, without bash, but if you need for some reason bash -i you can protect its run with setsid:

$ cat 1.sh
setsid bash -i -c 'sleep 1'
setsid bash -i -c 'sleep 1'
echo done

$ bash 1.sh
done
2
votes

The bash -i means run an interactive shell; so you have two shells both reading from the terminal.

Try removing the -i options.

2
votes
system "addmothernode"; 

should work.


To execute a command, bash is not needed. The Perl system function is like the system C function, it calls by default sh.

man system

exec

The standard to which the caller conforms determines which shell is used. See standards(5).

Standard                                      Shell Used
______________________________________________________________
1989 ANSI  C,  1990  ISO  C,  1999  ISO  C,   /usr/xpg4/bin/sh
POSIX.1  (1990-2001),  SUS,  SUSv2,  SUSv3,
XPG4
POSIX.1 (1988), SVID3,  XPG3,  no  standard   /usr/bin/sh
specified