setting path in command window using perl

Discussion in 'Perl Misc' started by Amish Rughoonundon, Aug 9, 2010.

  1. Hi,
    here is my problem. I have a perl script that executes multiple
    command line calls as follows:

    system("XCOPY", "$s_currentWorkingDirectory\\KCPSM3.EXE",
    $s_tempLocation, "/R", "/Y") == 0 or die "File KCPSM3.EXE could not be
    copied: $!\n";
    system("XCOPY", "$s_currentWorkingDirectory\\ROM_form.coe",
    $s_tempLocation, "/R", "/Y") == 0 or die "File ROM_form.coe could not
    be copied: $!\n";

    This is an example. There are many more with different programs being
    called.

    My problem is that I need to set the path to a certain batch file
    before calling the programs.

    It seems everytime I call system though, perl open a command window,
    executes the program and closes the window.

    So even if I set the path at the beginning, once system is done
    running, the path disappears.

    Can I force perl to run everything into only 1 command window.

    I hope I was clear with my question. Thanks a lot for the help,
    Amish
    Amish Rughoonundon, Aug 9, 2010
    #1
    1. Advertising

  2. Amish Rughoonundon <> wrote:
    >here is my problem. I have a perl script that executes multiple
    >command line calls as follows:

    [...]
    >My problem is that I need to set the path to a certain batch file
    >before calling the programs.


    No problem, just do so
    $ENV{PATH} = .......

    >It seems everytime I call system though, perl open a command window,
    >executes the program and closes the window.


    Of course. That is the semantic of system().

    >So even if I set the path at the beginning, once system is done
    >running, the path disappears.


    Of course. Environment variables are never inherited from the child to
    the parent.

    >Can I force perl to run everything into only 1 command window.


    Yes, you could. Just start all your external commands from the same DOS
    command line:
    system ("cmd1 & cmd2 & cmd3 & cmd4");
    But why?


    See also "perldoc -q environment":
    I {changed directory, modified my environment} in a perl script. How
    come the
    change disappeared when I exited the script? How do I get my changes
    to be visible?

    jue
    Jürgen Exner, Aug 10, 2010
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dino Buljubasic
    Replies:
    3
    Views:
    7,431
    Rob D
    Sep 25, 2004
  2. boriq
    Replies:
    4
    Views:
    583
    Tim Golden
    Jun 12, 2008
  3. Russell
    Replies:
    2
    Views:
    279
    Russell
    Sep 13, 2004
  4. Replies:
    2
    Views:
    159
    Tad McClellan
    Mar 26, 2005
  5. Paul
    Replies:
    5
    Views:
    440
    Eric J. Roode
    Dec 7, 2005
Loading...

Share This Page