| csmikle 2005-08-29, 9:04 am |
| Hi All
I am new to perl and programming (no previous programming background and did not recieve any answers in the beginners forum). 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->S
uspend();
$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 .doc file invokes word).
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.
How can I get around this.
O sooo close, but I have been stuck here for w s.
any help would be appreciated
Thanks in advance.
Charles |