CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Execute interactive c program from Perl using IPC on Windows

 



challss
New User

Nov 24, 2011, 4:38 AM

Post #1 of 5 (973 views)
Execute interactive c program from Perl using IPC on Windows Can't Post

Hi All, We are currently working on a perl script to interact with c program, which has both inputs and outputs. I have written following code to achieve this. I am unable to hold the script to prompt for the inputs. Please help.

a.exe does following
Please enter the 1st input : 2
Please enter the 2nd input : 3
and outputs
sum is 5

**********************************************
use IPC::Run qw(start pump finish);

my ($in, $out, $err);

# starting the application
my $handle = start 'D:\\a.exe', $in, $out, $err;
print 'hello';
# wait until prompted for input
pump $handle until $$out =~ /Please/;
$in .= "1\n";

# wait until prompted for password
pump $handle until $$out =~ /Please/;
$in .= "2\n";

print $out;
**********************************************

Regards,
Shyam


rovf
Veteran

Nov 24, 2011, 5:33 AM

Post #2 of 5 (970 views)
Re: [challss] Execute interactive c program from Perl using IPC on Windows [In reply to] Can't Post

I'm not sure that this type of communication will work when you run the program using "start". Is there a reason why you invoke it via "start"?

Aside from this, you didn't say what Perl you are using. Did you notice the following paragraph in the perldocs for IPC::Run?


Quote
Currently, pump() and run() only work on systems where select() works on
the filehandles returned by pipe(). This does *not* include ActiveState
on Win32, although it does work on cygwin under Win32 (thought the tests
whine a bit).


Ronald


challss
New User

Nov 24, 2011, 8:17 PM

Post #3 of 5 (966 views)
Re: [rovf] Execute interactive c program from Perl using IPC on Windows [In reply to] Can't Post

Thanks Ronald for your post. I tried various commands including open2, open3 and finally landed in Run, as its been suggested by someone when I googled for this issue. Can you please advice me about the best way to achieve this. As I am new to Perl, I really appreciate your help in this regard. BTW I am using strawberry perl.

Regards,
Shyam


rovf
Veteran

Nov 25, 2011, 1:14 AM

Post #4 of 5 (956 views)
Re: [challss] Execute interactive c program from Perl using IPC on Windows [In reply to] Can't Post

I wouldn't say Run is a bad idea. I use it myself. It's just that this kind of interaction you are trying, doesn't necessarily work - at least the perldocs say so.

I've never done this on Windows, so you should definitely google various forums to find people who had already driven interactive programs from Perl in Windows.

In any case, these are the alternatives I would try:

(A) To get the IPC::Run solution working:

- Since the perldocs explicitly mention ActiveState Perl as having a problem here, I would post this question on a ActiveState forum.

- I also would try the example with Strawberry Perl instead of ActiveState Perl.

- I would also see whether I can get it running in a Cygwin environment.

(B) To get an alternative solution working

- I would install Expect and see whether I can try it in that way. Here too, I have (at least) two choices: ActiveState Expect, and Cygwins Expect.

- If your system is configured in a way that you can telnet localhost, you could try Net::Telnet. I have used this once on Unix, but have no idea to what extent it works on Windows.


budman
User

Feb 11, 2012, 11:55 AM

Post #5 of 5 (830 views)
Re: [challss] Execute interactive c program from Perl using IPC on Windows [In reply to] Can't Post

hi

Trying to communicate to processes under Windows is much different than under Unix/Linux.

A quick search shows you will probably need a library to create Windows processes, and use the wperl.exe version that doesn't create a new window.

Check out this article, it should get you on the right path:
http://www.perlmonks.org/?node_id=851312

To find out more about IPC, read the perldoc perlipc it contains some very useful information.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives