running dos commands from perl script

E

edwells

My apologies for posting on this over hashed subject, but I need to set
up environment variables in DOS(XP) then execute a program using the
vars. I'm not having any problem with the individual commands, but
can't get the executable to to use the previously set variables.
Here's my code:

!/usr/bin/perl -w

system 'set var_1';
system 'set var_2';
system ' c:\progs~1\runexe.exe jobname >c:\xx.xx';
 
R

Richard

My apologies for posting on this over hashed subject, but I need to set
up environment variables in DOS(XP) then execute a program using the
vars. I'm not having any problem with the individual commands, but
can't get the executable to to use the previously set variables.
Here's my code:

!/usr/bin/perl -w

system 'set var_1';
system 'set var_2';
system ' c:\progs~1\runexe.exe jobname >c:\xx.xx';
system 'set var_1 && set var_2 && c:\progs\runexe.exe jobname c:\xx.xx'
 
E

edwells

Thanks,
That worked perfectly.


Sherm said:
Each call to system() launches a new child task, each of which has its own
set of environment variables that are unrelated to the previous child task.

But, a child's environment variables are inherited from the parent. So what
you could do is manipulate %ENV (perldoc perlvar) in your parent script
instead of using system() to run "set" commands. Something like this:

#!/usr/bin/perl

use warnings; # Preferable over -w
use strict; # You forgot that...

# obviously just example values and command...
$ENV{'var_1'} = 'val_1';
$ENV{'var_2'} = 'val_2';
system 'do stuff';

sherm--
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top