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: Advanced:
how do i run c program within perl?

 



menchen
User

Jul 18, 2000, 10:29 PM

Post #1 of 3 (624 views)
how do i run c program within perl? Can't Post

i need some help please.

how do i run a c compiled program(a.out) within perl?

the c program will need some string or number inputs and give one or more outputs.

how do i feed the c program inputs and get outputs with perl without using a temp file for storage?

thanks alot..

jason


Kanji
User / Moderator

Jul 25, 2000, 3:23 AM

Post #2 of 3 (624 views)
Re: how do i run c program within perl? [In reply to] Can't Post

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

my $prog = "/path/to/some/program";


exec( "$prog -arg this" );
exec( $prog, "-arg", "this" ); # No shell


system( "$prog -arg this" );
system( $prog, "-arg", "this" ); # No shell


`$prog -arg this`; # Those are backticks
qx/$prog -arg this/;


open PROG, "$prog -arg this |"; # Read only
open PROG, "| $prog -arg this"; # Write only</pre><HR></BLOCKQUOTE>

There are still more methods using open and the special filenames |- and -|.

If you can't supply your inneed to read from and write to a process, you'll need to use something like IPC::Open2 or IPC::Open3, or grow your own with pipe and select.

See perlipc, and the Functions for processes and process groups section of perlfunc for for more help.


menchen
User

Jul 26, 2000, 7:43 AM

Post #3 of 3 (624 views)
Re: how do i run c program within perl? [In reply to] Can't Post

thanks alot.

right now, i am using the following code.

#assume that the c program takes inputs from #command line.
open (PROG, "program $var1 $var2|") or die ($!);

#get outpout
while (<PROG> ) {
print;
}

thank you very much for replying.

 
 


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

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