markusk has asked for the wisdom of the Perl Monks concerning the following question:
But the code did not work at all - it froze on the <RR> block. So I went ahead a compiled a simple C code to simulate the problem.use strict; use warnings; use IPC::Open2; my $cmd = 'C:\temp\abc.exe'; my $pid = open2(*RR,*WW,$cmd); print WW "5 \n"; print WW "iAmString \n"; print WW "\n"; # any key while (<RR>) { chomp($_); print "$_\n"; } print "done \n";
And, the perl script was stuck at the blocking <RR> as expected. I changed the C Program and removed the 'system("pause") - press any key to continue' command, and it worked brilliantly. It appears to me that after the main part of the C program is executed it is blocked by 'cmd.exe /c PAUSE' that I believe is spawned as a blocking child process. i.e i can't write "<any key>" to the process I created through open2. Rather I might have to send <any key> to the cmd.exe that was spawned as a child of abc.exe. Is there a workaround for this? (I don't have access to the source code of the executable, so i can't simply remove the system("PAUSE"). Help is a appreciated.int main(int argc, char** argv) { printf ("Hello World \n"); int value1; printf ("I am a number: "); scanf("%d", &value1); printf ("This is your number: %d \n",value1); char ppp[20]; printf ("I am a string: " ); scanf("%s",&ppp); printf ("This is your string? %10.10s \n",ppp); // system("PAUSE"); return (EXIT_SUCCESS); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl Open2/3 and .exe
by ikegami (Patriarch) on Jun 17, 2009 at 21:15 UTC | |
|
Re: Perl Open2/3 and .exe
by ikegami (Patriarch) on Jun 17, 2009 at 21:31 UTC |