| Author |
example in perl c++
|
|
| Shashank 2004-07-06, 3:59 pm |
| Hi All,
Can anyone direct me to some good site that has simple examples to show
how to invoke or write C++ code that can be invoked by perl script?
regards,
Shashank
| |
| Purl Gurl 2004-07-06, 8:57 pm |
| Shashank wrote:
> Can anyone direct me to some good site that has simple examples to show
> how to invoke or write C++ code that can be invoked by perl script?
system ("c_code.exe");
$return = `c_code.exe`;
system ("system_c_interpreter c_code.c");
use Inline C => .etc
Simply execute your c code or use a c interpreter which
compiles and executes on-the-fly. Inline C will allow
you to embed C code.
Purl Gurl
| |
| Peter J. Acklam 2004-07-06, 8:57 pm |
| Shashank <shashank@icmgworld.com> wrote:
> Can anyone direct me to some good site that has simple examples
> to show how to invoke or write C++ code that can be invoked by
> perl script?
You can't "invoke" C++ code. However, you can invoke programs
compiled from C++ code. Or do you want to embed C++ code in your
program?
Peter
--
#!/local/bin/perl5 -wp -*- mode: cperl; coding: iso-8859-1; -*-
# matlab comment stripper (strips comments from Matlab m-files)
s/^((?:(?:[])}\w.]'+|[^'%])+|'[^'\n]*(?:''[^'\n]*)*')*).*/$1/x;
| |
| Shashank 2004-07-07, 3:56 am |
| I want to invoke C++ compiled programme from perl script.
regards,
Shashank
"Peter J. Acklam" wrote:
> Shashank <shashank@icmgworld.com> wrote:
>
>
> You can't "invoke" C++ code. However, you can invoke programs
> compiled from C++ code. Or do you want to embed C++ code in your
> program?
>
> Peter
>
> --
> #!/local/bin/perl5 -wp -*- mode: cperl; coding: iso-8859-1; -*-
> # matlab comment stripper (strips comments from Matlab m-files)
> s/^((?:(?:[])}\w.]'+|[^'%])+|'[^'\n]*(?:''[^'\n]*)*')*).*/$1/x;
| |
| Shashank 2004-07-07, 3:56 am |
| Thanks it works.
I tried to invoke an exe and it worked.
Where can i get more complicated examples like compiling a C++ programmed,
passing arguments to the programme etc.
regards,
Shashank
Purl Gurl wrote:
> Shashank wrote:
>
>
>
> system ("c_code.exe");
>
> $return = `c_code.exe`;
>
> system ("system_c_interpreter c_code.c");
>
> use Inline C => .etc
>
> Simply execute your c code or use a c interpreter which
> compiles and executes on-the-fly. Inline C will allow
> you to embed C code.
>
> Purl Gurl
| |
| Joe Smith 2004-07-07, 8:57 am |
| Shashank wrote:
[color=darkred]
> I want to invoke C++ compiled programme from perl script.
>
The "problem" is too trivial to need a site to explain it.
1) Write a C++ program.
2) Compile it and create an executable binary.
3a) Invoke your program from the command line with appropriate arguments.
3b) Invoke your program from a perl script using system() or $_=qr''.
For step 3b, it does not matter whether the program is written in C, C++,
assembler, etc.
Check the docs on the system() function and the use of backticks `` or qx//.
-Joe
| |
| Peter J. Acklam 2004-07-07, 8:57 am |
| Shashank <shashank@icmgworld.com> wrote:
> Where can i get more complicated examples like compiling a C++
> programmed, passing arguments to the programme etc.
You use the same functions, exec(), system(), ``, or open(). See
perldoc -f exec
perldoc -f system
perldoc -f open
and, for ``, see
perldoc perlop
Peter
--
#!/local/bin/perl5 -wp -*- mode: cperl; coding: iso-8859-1; -*-
# matlab comment stripper (strips comments from Matlab m-files)
s/^((?:(?:[])}\w.]'+|[^'%])+|'[^'\n]*(?:''[^'\n]*)*')*).*/$1/x;
| |
| Purl Gurl 2004-07-07, 3:58 pm |
| Shashank wrote:
> Purl Gurl wrote:
(snipped)
[color=darkred]
> I tried to invoke an exe and it worked.
> Where can i get more complicated examples like compiling a C++ programmed,
> passing arguments to the programme etc.
There are thousands of internet sites available for
your research and reading. Use a search engine.
Compile this c script beneath my signature and
run it from Perl for a simple example.
#!perl
system ("prntargu.exe one two three");
exit;
Four input arguments will be printed by that
Perl script example.
Purl Gurl
--
/* File: prntargu.c Purpose: print input arguments */
#include <stdio.h>
int main (int argc, char* argv[])
{
int i;
for (i=0; i<argc; i++)
printf("Input Argument: %s\n", argv[i]);
return 0;
}
| |
| Peter J. Acklam 2004-07-07, 3:58 pm |
| Purl Gurl <purlgurl@purlgurl.net> wrote:
> Shashank wrote:
>
>
Shashank, you'll save yourself lots if trouble and frustration if
you avoid her poor advice.
[color=darkred]
> Compile this c script beneath my signature and
> run it from Perl for a simple example.
>
> #!perl
>
> system ("prntargu.exe one two three");
>
> exit;
Since you don't bother checking the exit value anyway, then it's
better to use
exec ("prntargu.exe one two three");
which at least gives the caller a chance to check the exit value.
> Four input arguments will be printed by that
> Perl script example.
Except that "prntargu.exe" only has three input arguments.
Peter
--
#!/local/bin/perl5 -wp -*- mode: cperl; coding: iso-8859-1; -*-
# matlab comment stripper (strips comments from Matlab m-files)
s/^((?:(?:[])}\w.]'+|[^'%])+|'[^'\n]*(?:''[^'\n]*)*')*).*/$1/x;
| |
| Purl Gurl 2004-07-07, 3:58 pm |
| Peter J. Acklam continues to ignorantly troll:
> Purl Gurl wrote:
(snipped bad information from Acklam)
[color=darkred]
[color=darkred]
> Except that "prntargu.exe" only has three input arguments.
Clealy you know nothing about C programming and
very little about Perl programming.
Input Argument: C:\APACHE\USERS\TEST\PRNTARGU.EXE
Input Argument: one
Input Argument: two
Input Argument: three
You have forgotten you have me killfiled.
Do not to forget this in the future. Your constant
troll articles here and elsewhere wastes reader's time.
Purl Gurl
| |
| Peter J. Acklam 2004-07-07, 3:58 pm |
| Purl Gurl <purlgurl@purlgurl.net> wrote:
> Peter J. Acklam continues to ignorantly troll:
>
> Clealy you know nothing about C programming and
> very little about Perl programming.
I'm not going to argue against that. I'll let the readers make up
their own mind about who is the troll.
> Input Argument: C:\APACHE\USERS\TEST\PRNTARGU.EXE
> Input Argument: one
> Input Argument: two
> Input Argument: three
The output of the program is misleading. It is true that the name
of the program ends up in the in the *argument vector*, but the
name of the program is not an *input argument* to the C program.
> You have forgotten you have me killfiled.
You have said that three times, and I have already said it is not
true.
Peter
--
#!/local/bin/perl5 -wp -*- mode: cperl; coding: iso-8859-1; -*-
# matlab comment stripper (strips comments from Matlab m-files)
s/^((?:(?:[])}\w.]'+|[^'%])+|'[^'\n]*(?:''[^'\n]*)*')*).*/$1/x;
| |
| Purl Gurl 2004-07-07, 3:58 pm |
| Peter J. Acklam continues to ignorantly troll:
[color=darkred]
> Purl Gurl wrote:
(snipped)
[color=darkred]
You have forgotten you have me killfiled.
Purl Gurl
| |
| bvijayk 2004-10-18, 2:32 am |
| Hi Joe
I have compiled a set of CPP programs and got an Object file. Can I execute that code also in the same fashion as you have explained. I am able to execute that object code from the cmd prompt by using ./myObjCode. But unable to do the same thing from within a perl script.
Kindly help me out.
Thanks
Vijay
quote: Originally posted by Joe Smith
Shashank wrote:
[color=darkred]
> I want to invoke C++ compiled programme from perl script.
>
The "problem" is too trivial to need a site to explain it.
1) Write a C++ program.
2) Compile it and create an executable binary.
3a) Invoke your program from the command line with appropriate arguments.
3b) Invoke your program from a perl script using system() or $_=qr''.
For step 3b, it does not matter whether the program is written in C, C++,
assembler, etc.
Check the docs on the system() function and the use of backticks `` or qx//.
-Joe
|
|
|
|