For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > August 2005 > controlling other program with perl









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author controlling other program with perl
csmikle

2005-08-25, 5:47 pm

Hi All

I am new to perl and programming (no previous programming background). However to fix a problem I had I decided to use perl.

basically I need perl to run an application, wait 30 seconds, then close the application.

I am using a windows environment and the application I need to run is a .ws file (IBM client access emulator for the AS400)

I came across "fork", but with my limited knowledge I could not get it to do all of the above.

Then I found "system", here is the string
***
system "C:/Program Files/IBM/Client Access/Emulator/Private/prd.ws";
***
this kicked off the application but had no way to close the application after it started it as "system" waits on the application to close.

Next I came across "Win32::Process ". I thought perfect, then in my test the following worked.
***
use Win32::Process;
use Win32; sub ErrorReport{
print Win32::FormatMessage( Win32::GetLastError() );
} Win32::Process::Create($ProcessObj,
"C:/winnt/system32/notepad.exe",
"notepad temp.txt",
0,
NORMAL_PRIORITY_CLASS,
".")|| die ErrorReport(); #$ProcessObj->Suspend();
$pid = $ProcessObj->GetProcessID();
$exitcode = $ProcessObj->GetExitCode($exitcode);
$ProcessObj->Wait(20000);
Win32::Process::KillProcess($pid, $exitcode);
***
So I thought I had my solution but then when I replaced
"C:/winnt/system32/notepad.exe",
with
"C:/Program Files/IBM/Client Access/Emulator/Private/prd.ws",
It failed as it seemed prd.ws is now no longer recognised as an execuatble.
So I found the real executable then did the following
***
use Win32::Process;
use Win32; sub ErrorReport{
print Win32::FormatMessage( Win32::GetLastError() );
} Win32::Process::Create($ProcessObj,
"C:/Program Files/IBM/Client Access/Emulator/pcsws.exe",
"C:/Program Files/IBM/Client Access/Emulator/Private/prd.ws",
0,
NORMAL_PRIORITY_CLASS,
".")|| die ErrorReport();
# $ProcessObj->Suspend();
# $ProcessObj->Resume();
$pid = $ProcessObj->GetProcessID();
$exitcode = $ProcessObj->GetExitCode($exitcode);
$ProcessObj->Wait(30000);
Win32::Process::KillProcess($pid, $exitcode);
***
where pcsws.exe is the real executable and prd.ws is a profile that invokes pcsws when it is clicked. (kind of like a word or text document).

The problem here is that when pcsws runs and looks for the profile under the path for prd.ws, it reads up to the space in the path then prompts for the file. ie it does not read the entire path.

O sooo close, but I have been stuck here for ws, how can I have the entire path read.

any help would be appreciated

Thanks in advance.

Charles
csmikle

2005-08-29, 8:57 am

Is there anyone who can help with this

Thanks
Charles


quote:
Originally posted by csmikle
Hi All

I am new to perl and programming (no previous programming background). However to fix a problem I had I decided to use perl.

basically I need perl to run an application, wait 30 seconds, then close the application.

I am using a windows environment and the application I need to run is a .ws file (IBM client access emulator for the AS400)

I came across "fork", but with my limited knowledge I could not get it to do all of the above.

Then I found "system", here is the string
***
system "C:/Program Files/IBM/Client Access/Emulator/Private/prd.ws";
***
this kicked off the application but had no way to close the application after it started it as "system" waits on the application to close.

Next I came across "Win32::Process ". I thought perfect, then in my test the following worked.
***
use Win32::Process;
use Win32; sub ErrorReport{
print Win32::FormatMessage( Win32::GetLastError() );
} Win32::Process::Create($ProcessObj,
"C:/winnt/system32/notepad.exe",
"notepad temp.txt",
0,
NORMAL_PRIORITY_CLASS,
".")|| die ErrorReport(); #$ProcessObj->Suspend();
$pid = $ProcessObj->GetProcessID();
$exitcode = $ProcessObj->GetExitCode($exitcode);
$ProcessObj->Wait(20000);
Win32::Process::KillProcess($pid, $exitcode);
***
So I thought I had my solution but then when I replaced
"C:/winnt/system32/notepad.exe",
with
"C:/Program Files/IBM/Client Access/Emulator/Private/prd.ws",
It failed as it seemed prd.ws is now no longer recognised as an execuatble.
So I found the real executable then did the following
***
use Win32::Process;
use Win32; sub ErrorReport{
print Win32::FormatMessage( Win32::GetLastError() );
} Win32::Process::Create($ProcessObj,
"C:/Program Files/IBM/Client Access/Emulator/pcsws.exe",
"C:/Program Files/IBM/Client Access/Emulator/Private/prd.ws",
0,
NORMAL_PRIORITY_CLASS,
".")|| die ErrorReport();
# $ProcessObj->Suspend();
# $ProcessObj->Resume();
$pid = $ProcessObj->GetProcessID();
$exitcode = $ProcessObj->GetExitCode($exitcode);
$ProcessObj->Wait(30000);
Win32::Process::KillProcess($pid, $exitcode);
***
where pcsws.exe is the real executable and prd.ws is a profile that invokes pcsws when it is clicked. (kind of like a word or text document).

The problem here is that when pcsws runs and looks for the profile under the path for prd.ws, it reads up to the space in the path then prompts for the file. ie it does not read the entire path.

O sooo close, but I have been stuck here for ws, how can I have the entire path read.

any help would be appreciated

Thanks in advance.

Charles

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com