perl values for batch script to use

S

Slickuser

I have a filename (file.txt)

file.txt contains:
Sample4.1.2009_US
Sample4.2.2009_ASIA

I can parse this file in Perl fine. Now I want this value to be
available to use in a batch script.
I try using "set" but the info get clear once I exit perl script.


perl_script.pl
open file.txt
parse info
use system to execute command ("set xxyz_US=Sample4.1.2009_US")
("set xxyz_ASIA=Sample4.2.2009_ASIA")


batch.bat
call perl perl_script.pl
@echo on
@echo %xxyz_US%
@echo %xxyz_ASIA%
call perl script2. %xxyz_US% %xxyz_ASIA%

This %___% will be use in my other Perl scripts as well.

All I need to do is edit file.txt and the batch script will update the
value on it own through a schedule task.

What's a good solution to approach this?
 
A

A. Sinan Unur

I have a filename (file.txt)

file.txt contains:
Sample4.1.2009_US
Sample4.2.2009_ASIA

I can parse this file in Perl fine. Now I want this value to be
available to use in a batch script.
I try using "set" but the info get clear once I exit perl script.
perl_script.pl
open file.txt
parse info
use system to execute command ("set xxyz_US=Sample4.1.2009_US")
("set xxyz_ASIA=Sample4.2.2009_ASIA")

Those variables only exist in the shell that was invoked by the system
function call. By the time the call returns, that shell no longer
exists.

You can write out a batch file and CALL it from the other batch files.

Alternatively, you can set values in %ENV and invoke the batch files
from within your Perl script.

An example of the latter:

C:\Temp> cat one.bat
@echo %MYVAR1%

C:\Temp> cat two.bat
@echo %MYVAR2%

C:\Temp> cat t.pl
#!/usr/bin/perl

use strict;
use warnings;

$ENV{MYVAR1} = 'This is MYVAR1';
$ENV{MYVAR2} = 'This is MYVAR2';

system qw( one.bat );
system qw( two.bat );

__END__

C:\DOCUME~1\asu1\LOCALS~1\Temp> t
This is MYVAR1
This is MYVAR2

--
A. Sinan Unur <[email protected]>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
 
J

Jürgen Exner

Slickuser said:
I have a filename (file.txt)

file.txt contains:
Sample4.1.2009_US
Sample4.2.2009_ASIA

I can parse this file in Perl fine. Now I want this value to be
available to use in a batch script.

Please define "batch". I know that term only to describe a concept, but
not at the name of a programming or script language.
I try using "set" but the info get clear once I exit perl script. [...]
use system to execute command ("set xxyz_US=Sample4.1.2009_US")
("set xxyz_ASIA=Sample4.2.2009_ASIA")

Actually, that value is already cleared the moment, when the new process
that was used execute the external command terminated.

See 'perldoc -q env':
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
 
S

sln

What M$ calls a "batch script" is what is called a "shell script" by
most of the rest of the world.

So I guess Perl would be "batch script shell compiler"

-sln
 
S

sln

They're .bat files, flying in on little leathery wings to perform routine
tasks. :)

Windows calls daemons by the boring name of "services". Bleah.

How come thier not 1-liners you can enter on the command line, that do a lot of
program calls? When does it get it bat wings?

-sln
 
R

Ron Bergin

I have a filename (file.txt)

file.txt contains:
Sample4.1.2009_US
Sample4.2.2009_ASIA

I can parse this file in Perl fine. Now I want this value to be
available to use in a batch script.
I try using "set" but the info get clear once I exit perl script.

perl_script.pl
open file.txt
parse info
use system to execute command ("set xxyz_US=Sample4.1.2009_US")
("set xxyz_ASIA=Sample4.2.2009_ASIA")
Use setenv instead of the set command.

http://barnyard.syr.edu/~vefatica/#SETENV

Or, you could use the standard set command and then use Win32::API to
call 2 C functions (RegFlushKey and BroadcastSystemMessage) to force
that setting to be retained after the perl script ends, which is
basically what setenv does.

Win32::API
http://search.cpan.org/~cosimo/Win32-API-0.58/API.pm

RegFlushKey in Advapi32.lib
http://msdn.microsoft.com/en-us/library/ms724867(VS.85).aspx

BroadcastSystemMessage in user32.dll
http://msdn.microsoft.com/en-us/library/ms644932(VS.85).aspx
 
S

sln

Use setenv instead of the set command.

http://barnyard.syr.edu/~vefatica/#SETENV

Or, you could use the standard set command and then use Win32::API to
call 2 C functions (RegFlushKey and BroadcastSystemMessage) to force
that setting to be retained after the perl script ends, which is
basically what setenv does.

Win32::API
http://search.cpan.org/~cosimo/Win32-API-0.58/API.pm

RegFlushKey in Advapi32.lib
http://msdn.microsoft.com/en-us/library/ms724867(VS.85).aspx

BroadcastSystemMessage in user32.dll
http://msdn.microsoft.com/en-us/library/ms644932(VS.85).aspx

I don't understand posters taken verbatim. The dumb shmuks here
think a perl script can realistically shine shoes if asked. Literally.

-sln
 
R

Ron Bergin

I don't understand posters taken verbatim. The dumb shmuks here
think a perl script can realistically shine shoes if asked. Literally.

-sln


I don't understand how your comment applies to mine. What you're
trying to convey?
 
S

sln

I don't understand how your comment applies to mine. What you're
trying to convey?

Well Ron I guess I'm saying "Some little programs for Windows NT/Intel" isn't
relative in environments for a long time now. No longer are apps cluttering up
the environment. Maybe your just a little behind the times.

-sln
 
R

Ron Bergin

Well Ron I guess I'm saying "Some little programs for Windows NT/Intel" isn't
relative in environments for a long time now. No longer are apps cluttering up
the environment. Maybe your just a little behind the times.

-sln

Well, "Some little programs for Windows NT/Intel" is relative to the
OP and his environment.

The solution I suggested is a perfectly viable option for the OP's
problem. However, personally I'd use a different approach, but since
the OP didn't provide enough info on what he needs to accomplish, none
of us can say what that better approach should be.
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top