Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: .bat and perl mystery

by particle (Vicar)
on Jun 12, 2002 at 16:45 UTC ( #173921=note: print w/replies, xml ) Need Help??

in reply to .bat and perl mystery

#!/usr/bin/perl use strict; use warnings; $|++; my $cmd = 'hello world.bat'; my @cmd_args = qw/ testing testing 1 2 3 /; my $exit_code = system( $cmd, @cmd_args ); print 'exit code from ', $cmd, ' is ', $exit_code, $/;
and 'hello world.bat':
echo hello world! echo %1 %2 %3 %4 %5
does this work? system returns the exit code from the command. use backticks or qx// to get the program's STDOUT into a scalar or array.

~Particle *accelerates*

Replies are listed 'Best First'.
Re: Re: .bat and perl mystery
by Anonymous Monk on Jun 12, 2002 at 16:54 UTC
    This is it, but I don't think it will be of much help. In order to use "/USEENV", I first have to execute the batch file: 'vcvars32.bat'. If I execute it fromt he command line, things work fine, but when I call it in my script they don't
    sub Build { my $vcvars32 = 'VCVARS32.BAT'; system ($vcvars32); $command = join("", "msdev ", "$workspace", "\\", "$projectname ", + "\/MAKE ", "\"$name ", "\- ", "$activeconfiguration\" ", "\/REBUILD +\/OUT ", "$workspace\\", "$log_name ", "\/USEENV"); $start = localtime time; print "\nProcessing build..."; system "$command"; print "Done\n"; $finish = localtime time; }
      As you've found out, you can't set environment variables in the parent process. When you try, you spawn a new command process, set the environment variable and exit that process, losing whatever changes you made (see perldoc -q environment or here).

      What you can do is use the %ENV hash to set the environment before using VS to build your project.

      I can't remember what vcvars32.bat sets, but something like this:

      $ENV{LIB}='D:\VCDIR\LIB;' . $ENV{LIB}

      should work, as long as it is set before you begin the build.

        Sorry, I'm not sure I quit understand. Should I create a child process solely for the execution of the .bat file and the use the parent process to continue running the main script?

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://173921]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2022-05-21 08:14 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (76 votes). Check out past polls.