Reputation: 461
I am new to C++ coding.
I wanted to execute a Perl script (that controls an equipment) inside a C++ Visual Studio Win32 application. I was wondering what would be the most optimized approach in this regards?
Option 2 I have never used, but I am willing to learn and implement if that's the best way.
Upvotes: 1
Views: 1246
Reputation: 1
In my backup tool I once tried invoking system("perl script.pl")
, but it ran very slow on Windows (20-30 calls per second or so even though script.pl in a test benchmark did nothing). On Linux it was much, much quicker.
Upvotes: -1
Reputation:
I believe the "most optimized" approach is to embed Perl in your application.
Your second option is not really feasible, AFAIK. Since Perl is not compiled, your only other option would be to invoke the interpreter (e.g. through a system()
or exec()
-family call), as per your first option.
Now, there is quite a difference between embedding an interpreter in your code, and writing one line of code to call an external program, so you have to consider exactly how much optimization you need. The performance difference might even be minimal, so I strongly suggest that you try the easy way first, measuring your success.
Upvotes: 7
Reputation: 283733
I agree with Oystein that you're not likely to find a good way to compile the perl script into a shared library.
However, spawning perl from your C++ program isn't the only other option. You could also pipe data between the two programs, use a socket to pass data between them, and other IPC methods.
Upvotes: 4