joemaniaci has asked for the wisdom of the Perl Monks concerning the following question:
So I am attempting to call a perl script from C#/asp.net web form. However it isn't entirely calling it correctly and I have two examples
string fullPath = @"Z:\path\test.pl"; string arguments = arg1 + arg 2 Process myProcess = Process.Start(fullPath, arguments); myProcess.WaitForExit(999); if(!myProcess.HasExited) { myProcess.Kill(); throw new Exception("Timed out while running process"); }
Now the perl file I am trying to run accesses files and creates folders named after them. I have already ran this from the command prompt(Win 7/Strawberry Perl) with the same arguments just to double check that all the permissions are there and running perl test.pl works just as I expect it to. However, when I call the script from within asp.net a terminal does open but nothing happens. It just opens and closes, so I experimented by adding a sleep(xxx) to my test.pl and it actually affects when the terminal closes. So that tells me that asp.net is indeed opening a process and executing this perl script, but only the sleep command. However, when I changed the sleep from sleep(3) to sleep(10) I was actually able to see one of the print statements in the perl script print to the terminal for about a tenth of a second before the terminal closed. So I am not sure what is going on.
ProcessStartInfo perlStart = new ProcessStartInfo(@C:\Strawberry\perl\ +bin\perl.exe"); perlStart.Arguments = "Z:\path\test.pl" + argument1 + argument2; perlStart.UseShellExecute = false; perlStart.CreateNoWindow = true; Process perl = new Process(); perl.StartInfo = perlStart; perl.Start(); perl.WaitForExit();
Now this code is suppose to do the same thing, but the sleep commands have no effect on it whatsoever. The terminal barely opens before it closes. EDIT: Actually goofing around with it, it looks like it is is printing the good old file not found error with this one, it's just so fast. Looking for an asp.net process sleep function as we speak. So again, the perl file on it's own in the command prompt does everything flawlessly. sleep(xxx) commands with asp.net are actually being executed and under the right circumstances print statements are also being executed. However, under asp.net, new text files and folders are not being created. The purpose of this program is that I am converting my perl parser that handles text files as large as 30 GB into asp.net so that my tool has a web front end. However, asp.net can only handle files ~2 GB. I looked into creating a file splitter but from what I could tell, I would have used the same classes/methods used to open up the files and therefore would have run into the same 2 GB limit.
asp.net Process Class: http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx asp.net ProcessStartInfo Class: http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.aspxI should mention that having...
sleep(10) print "something";
...or...
sleep(5); print "something"; sleep(5);
...or...
print "something"; sleep(10);
...has no effect on the one print statement I can barely see for a split second.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Calling perl in C#
by davido (Cardinal) on Apr 18, 2012 at 20:10 UTC | |
by joemaniaci (Sexton) on Apr 18, 2012 at 20:25 UTC |