Solved

Perl and C++

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
This article will show, step by step, how to integrate R code into a R Sweave document
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

930 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

13 Experts available now in Live!

Get 1:1 Help Now