mndoci has asked for the wisdom of the Perl Monks concerning the following question:

Hello all,

This question is complicated in my mind, so I hope I put it down properly. Here is the scenario. I have a wrapper perl script which I use to set environmental variables and then start several processes. The first process is called by the following command (in the wrapper script)
system("$RUN_PROC1 $ARGV[0] $ARGV[1] $ARGV[2] $ARGV[3] $ARGV[4] $ARGV[5]");
where $ARGV[0] etc are command line flags and paths/filenames, and are then passed on to the subsequent script ($RUN_PROC1)which uses them to do some file processing and run some executables.
I want to follow this command with another, similar command
system("$RUN_PROC2 $ARGV[0] $ARGV[1] $ARGV[2] $ARGV[3] $ARGV[4] $ARGV[5]");
Will the command line parameters be passed on correctly? The two processes are separate perl scripts and use the SAME files etc pointed to by the command line parameters. For example, I have certain files that use the value of $ARGV[5], put it into a variable called $RUN_NAME and then append $RUN_NAME to a filename. I want to retain $RUN_NAME between PROC1 and PROC2.

Additionally I would like to retain and pass some PID's ($$)between PROC1 and PROC2.

I am not too sure about how to do this. Please not that there are subesequent processes which I would like to call from the wrapper script, which may share certain variables, although I do not think I will need to continue passing on the command line variables. If anyone can point me in the right direction it would be great. I have been looking at the IPC::Shareable module, but I am not sure that will do it.

Thanks

mndoci

"What you do in this world is a matter of no consequence. The question is, what can you make people believe that you have done?"-Sherlock Holmes in 'A study in scarlet'

Replies are listed 'Best First'.
Re: Passing command line variables and PID's between processes
by merlyn (Sage) on May 30, 2001 at 02:34 UTC
    Your shell-significant characters (such as whitespace and special chars) will be very badly messed up. Do this instead:
    system $RUN_PROC1, @ARGV; system $RUN_PROC2, @ARGV;
    That'll work cleanly and reliably for everything except NUL (\0) values in the array.

    -- Randal L. Schwartz, Perl hacker

Re: Passing command line variables and PID's between processes
by clintp (Curate) on May 30, 2001 at 02:36 UTC
    The same parameters should be passed on correctly, unless you've done something to muddle with @ARGV. I'd rewrite the system command to be a little more clear though:
    system("$RUN_PROCx @ARGV");
    Looks a lot nicer, and you don't have to worry about adding an $ARGV[6] should the need arise. As far as using the same PID number from process-to-process, those are assigned by the OS and there's no real way to coerce those. (If you're just passing them around, use them as an additional argument.) IPC::* is probably overkill.
Re: Passing command line variables and PID's between processes
by IraTarball (Monk) on May 30, 2001 at 02:58 UTC
    I know this doesn't address your original question but is there a reason you aren't calling system like this... system ($RUN_PROC2, @ARGV); Just asking. Now, if I understand, you 2 questions

    • Will your arguments, like $ARGV5, change before your second program gets to it?
    • How do you do interprocess communication with perl

    I don't think that your arguments will get toasted by system. If system did something like $_[5]='blown away'; you'd be screwed but, without checking, I'm pretty confident it operates on copies of your variables, not directly on @_.

    As for the second question check out pipes rather than shared memory for IPC. Not that my opinion matters much but I thinks pipes are easier to deal with and more stable than shared memory.

    "So... What do all these little arrows mean?"
    ~unknown

      Hi. Only reason I did not use @ARGV (which I am using now) is that I inherited these scripts and stuck to the original call. No $RUN_NAME is not changing between calls. There is only one weird error I am getting now and that seems to be related to the PID if anything at all.

      Thanks for your reply
      mndoci

      "What you do in this world is a matter of no consequence. The question is, what can you make people believe that you have done?"-Sherlock Holmes in 'A study in scarlet'