Solved

Perl and C++

Posted on 2006-06-30
5
169 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
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)
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now