Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: Invoking a perl program via an executable c++ program...

by trantor (Chaplain)
on Nov 14, 2001 at 20:11 UTC ( #125340=note: print w/replies, xml ) Need Help??

in reply to Invoking a perl program via an executable c++ program...

It is easily accomplished using the system() function (which is available in C, C++ and basically every other language, sometimes with a different name and/or namespace) #included from stdlib.b

Perhaps it is even better to make your perl program easier to use, without the need of any wrappers? :-) Unless you're exercising your C/C++ skills in string manipulation and program invocation of course.


Replies are listed 'Best First'.
Re: Re: Invoking a perl program via an executable c++ program...
by BigJoe (Curate) on Nov 15, 2001 at 01:15 UTC
    I am brushing up on my C/C++ and I am trying to run Perl scripts to do some stuff in my C/C++ program. So what I am wondering how does system in C/C++ allow you to capture the output of that script? Or do I need to keep digging into popen? Thanks


    Learn patience, you must.
    Young PerlMonk, craves Not these things.
    Use the source Luke.

      popen is really much simpler than what you think, just have a look at the manpage.

      If you want to use system, keep in mind that it does not return the output of the program you want to run, but since the command is interpreted by the shell you can actually redirect stdout and/or stderr with something like:

      system("command -options args > outfile");

      and then read outfile

      A third, much more exciting alternative, is to play with pipe, fork, dup, exec and do yourself what popen does. After this, you'll treat shell writers with much more respect :-)

      -- TMTOWTDI

Re: Re: Invoking a perl program via an executable c++ program...
by kiat (Vicar) on Nov 14, 2001 at 21:04 UTC
    Thanks :) At the moment, the perl program I've coded is invoked at the command line. I want to make it easier for others to use it by double-clicking a c++ program with the extension .exe. Can I do that with just perl itself or do I need to use c++ to write the so called interface?
      You can double-click on files with .pl, .perl, .wperl, etc. if you want. The GUI shell should ask you what to do the first time you try.

      I'm guessing you want to hide the console output and have the wrapper use a Window instead? Use wperl (or is it perlw?) .exe instead of perl.exe to run the script.


      If you're using ActiveState's Perl distro, under the Perl\bin dir there's a runperl.bat. If you copy that file to the same directory that your perl script is in, and rename the .bat file to have the same name as the perl script (ex: if your perl script is '', rename the .bat file to 'program.bat') - then someone at a command prompt should be able to just type 'program' or whatever the name of the script is to execute it.

      Of course, windows should have associated the .pl extension to Perl as John mentioned, so you should just be able to double-click on the file itself. in windows. :)

        I need the user to key in some inputs (arg1 and arg2) after the program is invoked (i.e. he or she need only to specify the arguments but not type out the entire command as in c:\perl>perl arg1 arg2). Ideally, I would like to have the user simply select the options (the arguments) through a GUI interface without having to type at the command line. Can that be done with perl alone or do I need to use c++ to do the interface? Thanks in advance.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://125340]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (2)
As of 2023-12-10 06:34 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (38 votes). Check out past polls.