tags:

views:

115

answers:

2

Hello:

I was following one of the thread to run perl scripts from my c# program.

My c# code is like this:

   private void RunScript(ArrayList selectedScriptFileList)
    {
        foreach (var curScriptFileName in selectedScriptFileList)
        {
            ProcessStartInfo myProcessStartInfo = new ProcessStartInfo("perl.exe");
            myProcessStartInfo.Arguments = (string)(curScriptFileName);
            myProcessStartInfo.UseShellExecute = false;
            myProcessStartInfo.RedirectStandardOutput = true;
            myProcessStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            myProcessStartInfo.CreateNoWindow = true;
            myProcess.StartInfo = myProcessStartInfo;


            myProcess.Start();
            myProcess.WaitForExit();
            string output = myProcess.StandardOutput.ReadToEnd();
            this.ScriptTestResultTextBox.AppendText(output);
        }            
    }

And my perl script requires XML parsing. I can read the print statement before the XML parsing, but not after the parsing starts. The script runs find on DoS shell.

Here is part of my script:

print("\n");
print("****************** test1.pl ***********************\n");
print("\n");

print("1");
print("2");

my $scriptName = 'test1.pl';
my $file = '../../ScriptParamLib.xml';
my $parser = XML::LibXML->new();
my $tree = $parser->parse_file($file);
my $root = $tree->getDocumentElement;
my @species = $root->getElementsByTagName('test_node');

print("Accessing XML Data Base...\n");

The c# testbox only shows the first three print statement but not the last one. Does anybody knows why?

Thanks

+4  A: 

You could add more debugging print statements (e.g. one between every other line of your code) to see how far the execution gets. However, I'm going to go on a hunch and suggest that adding these three lines to your script will either solve the problem outright or lead you closer to a solution:

use strict;
use warnings;
use XML::LibXML;

Please update your question indicating how far execution gets and what errors you see!

Ether
A: 

I figured I should roll my comments into an answer since they proved to be helpful:

Since using an absolute path for $file in the Perl script works, the issue most likely has something to do with the working directory of the process that gets spawned from the C# program. You can use the Cwd module in the Perl script to see what the working directory actually is. If it's not what you expect, try setting it via the WorkingDirectory property of ProcessStartInfo in your C# program. Relative paths should work just fine after that.

bish