Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I send data to and call dll or executable in perl?

Status
Not open for further replies.

pecan204

Programmer
Jan 25, 2001
24
0
0
US
Hello everyone,

I wonder if I can get some pointers on were to look?

I would like to bring data in from a form or upload file.
Send data that was input or uploaded to program by calling DLL or executable from script that is written in fortran.

What are your thoughts?
 
look at perldoc -f system

This will allow you to make a call, through a shell-like interface, to an external program. This should help, just make sure that you don't allow commands to be sent to the shell, or you're asking for trouble.

MWB.

Quick Example from perldoc:

@args = ("command", "arg1", "arg2");
system(@args) == 0
or die "system @args failed: $?" As always, I hope that helped!

Disclaimer:
Beware: Studies have shown that research causes cancer in lab rats.
 
If you want to catch the output of the fortran executable, you can open a pipe to it....


$cmd = "fortran_critter arg1 arg2 arg3";
open(PIPE,"$cmd |") or die "Failed to open pipe to $cmd, \n $!\n";
while (<PIPE>) { $output .= $_ ; }
close PIPE;


keep the rudder amid ship and beware the odd typo
 
Thanks for the answers. I've been stewing on this as it appears this is a couple of notches deeper than the Hunley for me.

Should I be using both pieces of code below?
Where would path be listed to executable?

#!/usr/bin/perl

@args = (&quot;fortran.exe&quot;, &quot;input1&quot;, &quot;input2&quot;);
system(@args) == 0 or die &quot;system @args failed: $?&quot;

$cmd = &quot;fortran.exe output1 output2 output3&quot;;
open(PIPE,&quot;$cmd |&quot;) or die &quot;Failed to open pipe to $cmd, \n $!\n&quot;;
while (<PIPE>) { $output .= $_ ; }
close PIPE;

Thanks again!
 
You would not use both. Use one or the other. Which one???? Well, the system call is nice and simple. It will fork a new process, wait for it to complete and returns the exit value for the executed program. NOTE that it does not return the output from the executed program. If all you want to do is run the program, then use system( or backticks). If you want to catch the output of your fortran critter, then you need to open a pipe to it.

In either case, just put the path in front of the file name....
@args = ('/path/to/fortran.exe','arg1','arg2');
$status = (system(@args))/256;
# the exist statuses returned by system are a little weird
# that is why divide by 256. Unless you need it, I won't go into that.

OR

$cmd = '/path/to/fortran.exe arg1 arg2 arg3';
open(PIPE,......same as in previous post....


HTH


BTW, the Hunley is in pretty shallow water now. ;-)


keep the rudder amid ship and beware the odd typo
 
Thanks Goboatin, As always a reliable and in depth source.

Got to do some coding now.

On that Hunley, I expect to be walking around it some day.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top