[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

C# running external command prompt programs on C# programs

Posted on 2010-11-10
8
Medium Priority
?
1,046 Views
Last Modified: 2013-12-17
Hi there! I am trying to allow my C# program to run an external perl script and output the results on a rich text box on a form. The problem arises with an error of:

Unhandled Exception: System.ComponentModel.Win32Exception: The system cannot fin
d the file specified
   at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startI
nfo)
   at System.Diagnostics.Process.Start()
   at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start(String fileName, String arguments)
   at ConsoleCommands.Program.Main(String[] args) in C:\Users\Aaron\Desktop\Sys
crawl\ConsoleCommands\ConsoleCommands\Program.cs:line 14

My codes as the following:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;


namespace ConsoleCommands
{
    class Program
    {
        static void Main(string[] args)
        {
            Process.Start("perl.exe", "C:\\syscrawl\\ftk\\bin\\mactime.pl -b testing.bodyfile -z UCT-8 > testing.txt");
        }
    }
}

Open in new window


When running the command purely on the CMD it works perfectly! Can someone please guide me to the problem? And can you please provide some clues for the output of the results to a rich text box for the C# form? Thanks!
0
Comment
Question by:VMthinker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
8 Comments
 
LVL 19

Accepted Solution

by:
arif_eqbal earned 900 total points
ID: 34109495
looks like you need to specify the path to Perl.exe
i think when you say it runs fine from cmd prompt you would already be in the path where this exe lies...
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34109588
or is perl.exe is already in $PATH then you could try:
Process process = new Process();
process.StartInfo.Filename = "C:\\syscrawl\\ftk\\bin\\mactime.pl"
process.StartInfo.Arguments = "-b testing.bodyfile -z UCT-8 > testing.txt";
process.ShellExecute = false;
process.RedirectStandardOutput = true;
process.Start();

System.IO.StreamReader reader = process.StandardOutput;  
string sRes = reader.ReadToEnd();  
reader.Close(); 

Open in new window

0
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 600 total points
ID: 34109592
Actually, scratch that, you still need perl.exe if you want to catch the output:
Process process = new Process();
process.StartInfo.Filename = "C:\\path_to_perl\\perl.exe";
process.StartInfo.Arguments = "C:\\syscrawl\\ftk\\bin\\mactime.pl -b testing.bodyfile -z UCT-8 > testing.txt";
process.ShellExecute = false;
process.RedirectStandardOutput = true;
process.Start();

System.IO.StreamReader reader = process.StandardOutput;  
string sRes = reader.ReadToEnd();  
reader.Close();  

Open in new window

0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 2

Author Comment

by:VMthinker
ID: 34133628
Carl your codes were all wrong!

It should be something like this:

ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.FileName = "C:\\path_to_perl\\perl.exe";
            startInfo.Arguments = "C:\\syscrawl\\ftk\\bin\\mactime.pl -b testing.bodyfile -z UCT-8 > testing.txt";
            startInfo.UseShellExecute = false;
            startInfo.RedirectStandardOutput = true;
            Process.Start(startInfo);

Open in new window


Please submit codes that VS 2010 can read. Thanks!
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34134303
The code was not ALL wrong!! Ok, a couple of the properties belong to the StartInfo, but that's what you get coding from memory!!

The rest is correct, and you obviously managed to figure it out for yourself, so hey maybe you learned something.
0
 
LVL 2

Author Comment

by:VMthinker
ID: 34134977
The error still remains?.....
0
 
LVL 2

Author Closing Comment

by:VMthinker
ID: 34136821
No complete codes were given.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question