dstew dstew - 2 months ago 11
Perl Question

Running a perl script that uses a prompt through a C# application

Trying to call a perl script from my c# app. The perl script has a prompt that requires the user to enter something into it. I can't seem to get it to display. This is the function i use to call it. I have another function that sets the System.Enviroment.SetEnvironmtVariable to have the path of "C:\Perl\bin\;" along with other ones needed for other process'

private void getRevisionAndUpdate()
{
Process myProcess = new Process();
myProcess.StartInfo.FileName = "cmd.exe";
myProcess.StartInfo.WorkingDirectory = @"the directory that has the perl script";
myProcess.StartInfo.Arguments = @"/c SaidPerlScript.pl";
myProcess.StartInfo.UseShellExecute = false;
myProcess.Start();
myProcess.WaitForExit();
}


as i said before it seems to run, but it will either just open the script in a notepad or do nothing at all. Also should note i've tried running cmd.exe and perl.exe. cmd seems to open it in notepad and perl doesn't display the prompt it should.

rbm rbm
Answer

Not quite sure why you're trying to run cmd.exe, but it works if you run it via perl.exe (my script is called a.pl and prints hello):

    static void Main(string[] args)
    {
        Process myProcess = new Process();
        myProcess.StartInfo.FileName = "perl.exe";
        myProcess.StartInfo.WorkingDirectory = @".\";
        myProcess.StartInfo.Arguments = @"a.pl";
        myProcess.StartInfo.UseShellExecute = false;
        myProcess.Start();
        myProcess.WaitForExit();
    }

and it also correctly reads STDIN. For reference this is a.pl:

print("Hello\n");
my $a = <STDIN>;
print "You entered " . $a . "\n";
Comments