Yona has asked for the wisdom of the Perl Monks concerning the following question:

I have a project written in Perl, and I want to give it a nice interface, using windows forms. So that, with a click of a button that I will put on the form, the script will run as usual (with no need of Command Prompt). I am using windows environment (activePerl). Is it possible? if so, then how?

Replies are listed 'Best First'.
Re: Calling Perl script from windows form
by Anonymous Monk on Apr 30, 2014 at 07:23 UTC
      I know that, but I REALLY wanted to combine my perl script with C#. I guess I need to use command line. Thanks anyway :)
Re: Calling Perl script from windows form
by Anonymous Monk on Apr 30, 2014 at 11:17 UTC

    You can run external programs from C#, a quick Google brings up, for example, this. You would be calling perl.exe (or wperl.exe) with the appropriate arguments, i.e. the pathname of your script and any other arguments.

    I've found it's helpful to use absolute pathnames, and also to write the script such that it does not make any assumptions about the current working directory (it can use FindBin to figure out its location). A caveat: Using full pathnames means that those need to be hardcoded or configured, making the application a little less easy to move between differently laid out machines. I've found that in a somewhat controlled environment, full pathnames have been more helpful than not, others may disagree.

    As for really "integrating" Perl into C#, as in integrating an interpreter into your application, I'm not sure if that's possible or how easy or not it is. Maybe some other Monks have some experience on that. Apparently ActiveState offers some kind of .NET "integration".

    Lastly, as the other anon has pointed out, you can write GUIs in Perl (but then they wouldn't have anything to do with C#).

      ActiveState's ActivePerl does include "EzPerl.dll", which I would expect could be used by a C# application. Documentaton for it is part of the ActivePerl package.

Re: Calling Perl script from windows form
by locked_user sundialsvc4 (Abbot) on Apr 30, 2014 at 11:54 UTC

    As the latest Anonymous Monk did usefully say . . . from the point-of-view of your GUI application, the Perl script is simply an external program.   You simply need to build a command-line string containing the name of the script and any parameters, and execute that as you would any other external process.   If, as I expect, ActiveState has associated itself with the .pl filename extension, you ought to be able to just execute the script-file name.   (Naturally, you should start by fiddling-around with the proper way to do just-that within C#, until you get the necessary magic-spell just right.)

    One issue, though, will be coming up with an appropriate way for your GUI application to wait for the external process (the Perl script) to complete, without hanging-up the user interface as GUI-programs must never do.   Of course the Internet should be filled with examples of how to do that part.   (“Don’t sweat it, don’t [re-]invent it, just google find it ...”)   It really does not matter that the external program in question is written in Perl or anything else.   Then, carefully look for any discussions on the Internet that may particularly relate to ActiveState-specific issues in this case.

    Kindly observe that the external program (the script) will be a direct child-process of the GUI process:   it is not running under (Windows’s pathetic excuse for) a command-shell.

      ... build a command-line string... and execute that... you should start by fiddling-around with the proper way to do just-that within C#... an appropriate way for your GUI application to wait for the external process... the Internet should be filled with examples...

      The link in the post you referred to already provides solutions to both of these issues.