Not able to write using Open2

P

Paul Lalli

Ashwin said:
Here is my complete code ,

Your "complete code" doesn't compile. Try again. Copy and paste,
don't retype.

Also, from your description, are you sure you shouldn't be using the
Expect module from CPAN?

Paul Lalli
 
A

Ashwin

Here is my complete code , I am trying to call a file, and then I need
to pass cirtain inputes which script asks,
I am opening with open2 and then trying to write with WRITE, I am able
to read but cannot write I mean I cannot send the input to WRITE handle
what could be wrong
TIA

use warnings;
use strict;
use IPC::Open2;
use Cwd;

my $currentdir=cwd();
my $pid;
chdir ("/source/internal/") or die "Cannot Change Directory";
$pid = open2 (\*READ,\*MY_WRITE,"BuildInternal.pl") or die;

while (<READ>)
{
print $_;
}

print MY_WRITE\n";

while (<READ>)
{
print $_;
}

close MY_WRITE;
close READ;

--
 
A

Ashwin

Paul said:
Your "complete code" doesn't compile. Try again. Copy and paste,
don't retype.

Also, from your description, are you sure you shouldn't be using the
Expect module from CPAN?

Paul Lalli

SOrry, I missee one quatation
here is compiled code,
is there no way I can get it done with open2?


use warnings;
use strict;
use IPC::Open2;
use Cwd;

my $currentdir=cwd();
my $pid;
chdir ("/source/internal/") or die "Cannot Change Directory";
$pid = open2 (\*READ,\*MY_WRITE,"BuildInternal.pl") or die;

while (<READ>)
{
print $_;
}

print "MY_WRITE\n";

while (<READ>)
{
print $_;
}

close MY_WRITE;
close READ;

--
 
P

Paul Lalli

Ashwin said:
SOrry, I missee one quatation
here is compiled code,
is there no way I can get it done with open2?

Get *what* done? I don't see anywhere in the code below in which you
attempted to write to the process.
use warnings;
use strict;
use IPC::Open2;
use Cwd;

my $currentdir=cwd();
my $pid;
chdir ("/source/internal/") or die "Cannot Change Directory";
$pid = open2 (\*READ,\*MY_WRITE,"BuildInternal.pl") or die;

Here you open the process BuildInternal.pl, with a read filehandle READ
and a write filehandle MY_WRITE
while (<READ>)

Here you begin reading from READ
{
print $_;

Here you print the lines read from READ out to STDOUT
}

print "MY_WRITE\n";

Here you print the string "MY_WRITE\n" out to STDOUT
while (<READ>)

Here you again read from READ
{
print $_;

Here you again print the lines read from READ out to STDOUT
}

close MY_WRITE;
close READ;

Here you close both filehandles.

What part of this code were you expecting to write anything to the
MY_WRITE filehandle?

Paul Lalli
 
A

Ashwin

Paul said:
Get what done? I don't see anywhere in the code below in which you
attempted to write to the process.


Here you open the process BuildInternal.pl, with a read filehandle
READ and a write filehandle MY_WRITE


Here you begin reading from READ


Here you print the lines read from READ out to STDOUT


Here you print the string "MY_WRITE\n" out to STDOUT


Here you again read from READ


Here you again print the lines read from READ out to STDOUT


Here you close both filehandles.

What part of this code were you expecting to write anything to the
MY_WRITE filehandle?

Paul Lalli

Hi,
sorry for missing the valid part
this part of the script
print "MY_WRITE\n"; should have been
print MY_WRITE "4\n";
to clarify that value 4 need to be written in output handle and then a
carridge return so that called script gets value as 4

sorry for the trouble
--
 
I

Ian Wilson

Ashwin said:
Paul Lalli wrote:




sorry for missing the valid part
this part of the script


print MY_WRITE "4\n";

Do you mean that your script contained
print "MY_WRITE\n";
end you have now corrected it to
print MY_WRITE "4\n";
and everything is OK now?

Or do you mean your script contained the latter all along but that
instead of using copy & paste you are still retyping and making typing
mistakes. In which case you still want help?
to clarify that value 4 need to be written in output handle and then a
carridge return so that called script gets value as 4

IIRC on a Unix host, "\n" will emit a linefeed character, not the
carriage-return character you mention. This might be causing you problems?
 
A

Ashwin

Ian said:
Do you mean that your script contained
print "MY_WRITE\n";
end you have now corrected it to
print MY_WRITE "4\n";
and everything is OK now?

Or do you mean your script contained the latter all along but that
instead of using copy & paste you are still retyping and making
typing mistakes. In which case you still want help?


IIRC on a Unix host, "\n" will emit a linefeed character, not the
carriage-return character you mention. This might be causing you
problems?




Hi,
Let me clarify the situation without actual code,
:
I have a perl script which cannot be modified as its not maintained by
me, and it does not accepts command line parameter, once executed the
script provides options like (1,2,3,..7) which once selected the script
proceeds,

:
For that I tried to use open2, as
$prog="perl makefile.pl";
$pid = open2 (\*READ,\*MY_WRITE,$prog)

right after opening the $prog, I get Error out from $prog that I
selected unknown option, which should come if I execute the $prog
standalone and on select option I press "enter"->return ,
If I try to read from READ it blockes after printing till select option
is displayed on STDOUT, but If I print MY_WRITE with the option I want
want to execute form $prog before reading from READ it does not gets
block

A valuable inforamtion I missed, sorry for that, I am on win32 XP
machine so probably I cannot use perl Expect module



--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top