How To Run PERL Scripts In C#
Question
Monday, March 30, 2009 12:46 PM
Hi
I am currently writing an application in C# and I need it to call a PERL script to do some text processing. I have searched on a number of different forums and found some code which people have said should work but when I use it, the file is not processed.
The code I have is:
ProcessStartInfo perlStartInfo = new ProcessStartInfo("perl.exe");
perlStartInfo.Arguments = "Word_Splitter.pl " + inputFilePath + " > " + outputFilePath;
perlStartInfo.UseShellExecute = false;
perlStartInfo.RedirectStandardOutput = true;
perlStartInfo.RedirectStandardError = true;
perlStartInfo.CreateNoWindow = true;
Process perl = new Process();
perl.StartInfo = perlStartInfo;
perl.Start();
string output = perl.StandardOutput.ReadToEnd();
perl.WaitForExit();
I have tried playing around with the different settings in an attempt to get it to work but so far I have had no luck. I would appreciate any help anyone could give me on this.
The PERL script that I am attempting to run can be found here:
http://l2r.cs.uiuc.edu/~cogcomp/atool.php?tkey=WS
Thanks in advance
All replies (6)
Monday, March 30, 2009 1:10 PM ✅Answered | 2 votes
This is working for me
ProcessStartInfo perlStartInfo = new ProcessStartInfo(@"d:\Perl\bin\perl.exe");
perlStartInfo.Arguments = "c:\word-splitter.pl " + "c:\a.txt" + " ispell";
perlStartInfo.UseShellExecute = false;
perlStartInfo.RedirectStandardOutput = true;
perlStartInfo.RedirectStandardError = true;
perlStartInfo.CreateNoWindow = false;
Process perl = new Process();
perl.StartInfo = perlStartInfo;
perl.Start();
perl.WaitForExit();
string output = perl.StandardOutput.ReadToEnd();Thanks, A.m.a.L [Remember to click "mark as answered" when you get a correct reply to your question]
Monday, March 30, 2009 1:43 PM
Thanks for getting back to me about this so quickly.
I have made the changes to the settings that you had in your code and it worked straight away.
Thanks Again
Stuart
Wednesday, April 6, 2011 1:50 PM
I did the same thing as told.My perl script is very simple just printing Hello World. I use the output to be appeared in a text box but it doesn't print anything. I also debug the code the see the value in output but it appears to be null. Can you please help me?
Wednesday, April 6, 2011 2:37 PM
Seems like a coding issue.
Post the code you are working on.
Thanks, A.m.a.L [MVP Visual C#] Dot Net Goodies |
|
Don't hate the hacker, hate the code |
Wednesday, June 3, 2015 10:53 PM
I am trying to run just a simple PERL script without any output. What differences would I need to make to the above code, if i don't have any output?
Wednesday, June 3, 2015 11:07 PM
Could you post your entire c# file(s)?