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

I have coded a program in perl that will pass some variables to a bat file on my windows server, however I seem to be having issues when I call a system command. Once the system command gets called from Perl the variable gets lost. I understand this is due to it probably opening a new thread where the variables do not carry over. My question is how to get past that? Is there a way to pass the variables from perl to the bat file? Here is the part of the code where I am having issues with.
system('psexec.exe \\\\aisfs01.gcps.k12 -u username -p password "e:\p +soft\batfls\$product{commandstop}"') ;
If it runs as is above, I get the following error: "psexec could not start e:\psoft\batfls\$product{commandstop} on aisfs01"

Replies are listed 'Best First'.
Re: Export variables from perl to a bat file
by BrowserUk (Patriarch) on May 13, 2009 at 22:38 UTC

    It's often clearer to break up long command lines into bits.

    You could try the multi-arg version of system, but I'm never quite sure what goes on under the covers and find myself guessing how to arrange for things to get interpolated and quoted correctly. DIY often seems easier to me.

    Try:

    system join ' ', 'psexec.exe', '\\\\aisfs01.gcps.k12', '-u username', '-p password', qq[ "e:\\psoft\\batfls\\$product{commandstop}" ] ;

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Thanks guys. I took the recommendations of both posts above, and got it working, only to realize that the system does not capture the output. I ended up going the route of a backtick operator which will allow me to capture the output.
Re: Export variables from perl to a bat file
by oxone (Friar) on May 13, 2009 at 22:27 UTC
    If you want to interpolate variables like $product{commandstop} into your system call you need to enclose the whole string in double quotes not single quotes (and having done that you'll need to escape the literal double quotes in the system call by backslashing them).
Re: Export variables from perl to a bat file
by generator (Pilgrim) on May 14, 2009 at 06:53 UTC
    I don't know how complex or long your batch file is but when I do this sort of thing, my habit has been to rewrite the entire batch file rather than trying to pass variables to a static batch file.

    Then its simply a matter of executing the batch file with all necessary info included.

    Admittedly this is not an answer to your question but is an alternative approach to the underlying requirement.

    <><

    generator