Solved

Perl and C++

Posted on 2006-06-30
5
197 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
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 a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

751 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