Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Perl and C++

Posted on 2006-06-30
5
Medium Priority
?
221 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 300 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
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.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

670 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