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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

system() question???

Status
Not open for further replies.

daveniemann

IS-IT--Management
Aug 25, 2002
7
0
0
US
I have a PERL file that launches several dos command line programs( using the system command)

it appears that it launches the first command and then immediatley moves to the next system commnad. I would like to launch the first command in a new window, peform the command, then terminate the window and THEN execute the next system command. any ideas on how to do this?

thanks in advance.

 
Dave,
When you say dos command line programs, do you mean commands that are text only or do they actually run commands that start windowed programs? (i.e. dir vs. winword).

If the commands start from a dos prompt and while the app is still running the command prompt returns, then that is how things will run under a system call.

If these are commands that start new processes you would need to use something like Win32::process and do a $proc->Wait(INFINITE) to make the perl script wait for the window app to exit before continuing.

Hope that helps.
 
I have found that perl will run right down the list of commands - whether they are specific to the shell or launch other applications. The only way to manage this is by getting a pid and waiting for it to exit. I use this extensively on Windows to do things like start, stop, and configure services, and install programs.

Here is a snippet of code from a script I wrote that would start a service using the Windows command line utility "SC.exe".

$app = "sc.exe";
$cmd = "sc.exe start Ingres_Database";
if(Win32::Spawn($app,$cmd,$Pid)) {
print "";
} else {
print "Installation aborted because of ";
die "error:" . Win32::FormatMessage(Win32::GetLastError());
}
waitpid($Pid,0);

Here is an article that explains more fully about this and different methods you can use to control processes.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top