Solved

Perl and C++

Posted on 2006-06-30
5
190 Views
Last Modified: 2013-12-25
Is it possible to execute a C++ 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.
0
Comment
Question by:ranadhir
5 Comments
 
LVL 19

Expert Comment

by:Kim Ryan
ID: 17022652
Yes, you can use the system command to run any application. If your C++ code is compiled to an exe just say:
system('/location/of/your/program.exe > output.txt'); # run external app, collecting redirected output
0
 

Author Comment

by:ranadhir
ID: 17022744
Thanks a lot for the post.
Actually i need to bring the stream from stdout back into perl;so i would need to collect in into a perl variable.Also the approach would need to allow passing input parameters to the console application?
 Is there an alternative to achieve these?
0
 
LVL 19

Expert Comment

by:Kim Ryan
ID: 17022783
You can pass arguments,  
system('/location/of/your/program.exe  param1 param2 ...');

Cpaturing stdout from perl is harder. You can capture the return code of the app, but this is probably not enough for you.
$ret_code = system('/location/of/your/program.exe  param1 param2 ...');  

If you redirect stdout to a text file, you can then open that file from perl and process its contents.
open(FH,"<'/location/of/your/output.txt');
@lines = <FH>;
0
 
LVL 28

Accepted Solution

by:
FishMonger earned 75 total points
ID: 17027209
If you need to capture the output of the program, use backticks instead of the system call.

@lines = `/location/of/your/program.exe  param1 param2 ..`;

or

@lines = qx(/location/of/your/program.exe  param1 param2 ..);
0
 
LVL 6

Expert Comment

by:nitinsawhney
ID: 17417828
FishMonger is correct.... but another important bit if you try to run this c++ script from web then it should be in the similar location or loacation where the apache has access.
Lots of restriction are imposed when you are calling an executable from a cgi script.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question