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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl and C++

Status
Not open for further replies.

ranadhir

Programmer
Joined
Nov 4, 2003
Messages
54
Location
IN
Is it possible to execute a C++ console application through perl.We have a windows console application which needs to be run recursively at specified interval ,and the output from stdout to be collected.
Since the framework we are integrating with this application, provides interfaces through perl script,we wanted to explore if the above option is possible.
If yes,samples or links will be very helpful.
 
From what you described, it sounds possible. You could launch your console with the system command and capture stdout to a file:

system("application.exe >> c:/temp/output.txt");

If you want to bring stdout into perl itself for processing, then use backticks `` to execute the program.

my $output = `application.exe`;

Raklet
 
Thanks a lot for the help.
I indeed have to collect the stream from stdout into perl itself.
So i believe the second option will be more suitable.
But in this option,will it be feasible to pass in input parameters to the console exe?
That is also one of the requirements of this application
 
Yes, you can pass parameters. Using the system or backticks commands are the same as if you are typing directly on the command line.

`notepad c:/temp/output.txt`;

Run notepad and pass file to open parameter.

Raklet
 
Thanks a lot for the advice;i am now able to pass parametrized arguements to application and invoke it.Thats a big progress - with a small hitch.When i pass in a xml string,it doesnt allow.

C:\perlexecs>perl backtick.pl '<root></root>' 20
< was unexpected at this time.

and sending it in as
C:\perlexecs>perl backtick.pl "'<root></root>'" 20,consumes the entire stream including the quotes.

Sorry for the trouble,but am almost at the last point of this endeavour with your help
 
You need the double quotes in order to pass the argument. Clean up the string once it is inside the perl script. Something like this:

Code:
my $data = shift @ARGV; # get the param pass at command line
$data =~ s/^'|'$//g; # remove the beginning and ending single quotes
print "This is $data\n";  # do something with it
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top