in reply to How to run bash file from perl

Method 1:
my $afile='dir1/firstfile.txt';<br> my $bfile='dir2/secondfile.txt';<br> my $bash_command='learn.sh '.$afile.' '.$bfile.' |';<br> open(my $output,$bash_command) or die $!;<br> while(my $line=<$output>){<br> print "$line";<br> }
Method 2:
my $afile='dir1/firstfile.txt';<br> my $bfile='dir2/secondfile.txt';<br> @args = ("learn.sh", $afile, $bfile); system(@args) == 0 or die "system @args failed: $?"
Method 3:
my $output=`learn.sh $afile $bfile`;
I tried three different ways as you all have suggested, but I couldn't make my script work. Please help me what is wrong in it

Binod

Replies are listed 'Best First'.
Re^2: How to run bash file from perl
by ciderpunx (Vicar) on May 18, 2011 at 12:24 UTC
    Hi Binod

    Would you like to tell us how it doesn't work? What are you expecting to see? What do you see? Are there any error messages? The more specific you are the more likely folk will be to help you out. You might want to review How do I post a question effectively?

Re^2: How to run bash file from perl
by anonymized user 468275 (Curate) on May 19, 2011 at 09:13 UTC
    If it hangs, it probably needs input, in which case IPC::Open2 or IPC::Open3 and print to the input channel of the subprocess, close it and read the output. But you still need to know what it expects and what to expect back. Try running the command directly and saving sample I/O to files, e.g. stdin.dat stdout.dat and stderr.dat. Then use these files as a template for designing your program around open2 or open3.

    hint; to save input to a file, use:

    echo ' stuff ' | tee stdin.dat | command.sh args >stdout.dat 2>stderr.dat

    One world, one people