Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using DOS commands in Perl

Status
Not open for further replies.

banjopicker

Programmer
Jan 22, 2004
4
US
I am running a perlscript on windows. To execute DOS commands within Perl, I have used "system 'dir';" within the Perl code. This example would execute a simple directory listing. The challenge I am having is... when I attempt to set a system variable, specifically "SET MQSERVER=SCCH/TCP/10.10.10.10(1414), it does not get set. I have also tried to execute an external command file that does the set and it does not work either. All other DOS commands seem to work fine...
Any suggestions?
thanks,
banjopicker
 
There's a built-in hash you need to set, for your example above you would say:

$ENV{MQSERVER}='SCCH/TCP/10.10.10.10(1414)';

system('whatever you need to do');

When Perl starts shell, a DOS session if you like, it creates one with the environment variables set according to the %ENV hash - which you set as above.

Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
Mike:
Thanks a lot for the information. I understand what you are saying about the environment for the shell and I was able to verify your response with a test. I guess the thing that bothers me is that I am using a perl script to prompt the user for which environment variable they want and then try to establish that environment and still run the same perl script. As it stands, I would have to run the script to prompt the user, have this script set the environment variables of another shell and then run yet another perl script within that shell. I see how it can be done but it seems a bit bulky. I wonder if there is a way to alter the session a script is running from within the same script.

In any case...thanks a bunch for the information.

Adios,
Banjopicker
 
You're using a Perl script to get some information from a user (the environment variable) and then running a DOS command after setting the $ENV{} value? That sounds fine to me.

Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
I guess it would be one thing if the original perl script, that prompts the user for env info, did a system call for the environment update and then came back and proceeded to process. But how I see it now is that the perl script in session #1 prompts the user for env info, does a DOS system call to session #2 to set the env var (does not update session #1) and then a subsequent system command is done to launch a new perl script (also in session #2) to complete the processing.

I really do appreciate your information. I am still kind of new to perl. Does this sound like how you would do this?

thanks again,
banjopicker

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top