Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Starting process throws "System can not file the file specified" excep 2

Status
Not open for further replies.

ralphtrent

Programmer
Jun 2, 2003
958
US
Hello
I have the following code
Code:
System.Diagnostics.Process lpEncryptPassword = new System.Diagnostics.Process();
lpEncryptPassword.StartInfo.UseShellExecute = false;
lpEncryptPassword.StartInfo.CreateNoWindow = true;
lpEncryptPassword.StartInfo.RedirectStandardOutput = true;
lpEncryptPassword.StartInfo.WorkingDirectory = @"f:\dot-net\c#\PWE\2.0\PWE";
lpEncryptPassword.StartInfo.FileName = "EncryptPassword.exe";
lpEncryptPassword.StartInfo.Arguments = UserName + " " + Password;
string lsEncryptPassword = "";
try
{
	lpEncryptPassword.Start();
        lsEncryptPassword = lpEncryptPassword.StandardOutput.ReadLine().Remove(0, 21);
}
catch { throw; }
finally
{
	lpEncryptPassword = null;
        GC.Collect();
}
return lsEncryptPassword;

When I run this I get the following execption
Code:
Message: "The system cannot find the file specified"

If I take out the
Code:
lpEncryptPassword.StartInfo.UseShellExecute = false;
lpEncryptPassword.StartInfo.RedirectStandardOutput = true;
The process runs with out an issue. I need to read the output of the exe since it writes the output I need on the command line. I did not write this exe so I can not change it. This code is inside a dot net 2.0 class, while my calling app is a 3.5 dot net app. Not sure if that makes a difference or not.

Any help is appreciated.

Thanks,
RalphTrent
 
thats the first place I looked and the solutions I tried did not work.
 
btw remove the catch{throw;} block. try{}finally{} is all you need. post the full stack trace as well. this will provide some insight into why it's failing.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
Here is the stack

Thanks
Code:
{"The system cannot find the file specified"}
    [System.ComponentModel.Win32Exception]: {"The system cannot find the file specified"}
    Data: {System.Collections.ListDictionaryInternal}
    HelpLink: null
    InnerException: null
    Message: "The system cannot find the file specified"
    Source: "System"
    StackTrace: "   at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)\r\n   at System.Diagnostics.Process.Start()\r\n   at TriZetto.Support.PWECore.Cls.Connection.GetEncryptedPassword(String UserName, String Password) in f:\\dot-net\\c#\\PWE\\2.0\\PWECore\\Connection.cs:line 96\r\n   at TriZetto.Support.PWECore.Cls.Connection.PWEConnection(Int32 Release, String Region, String ConnectionName) in f:\\dot-net\\c#\\PWE\\2.0\\PWECore\\Connection.cs:line 55"
    TargetSite: {Boolean StartWithCreateProcess(System.Diagnostics.ProcessStartInfo)}

Line 96 is
Code:
lpEncryptPassword.Start();
line 55 is calling this function.

 
I know the error message is obvoius, but the location to the file is valid because like I said, if you take out the redirectoutput and useshellexecute it works fine.

Thanks
 
ref quote
[tt]The WorkingDirectory property behaves differently when UseShellExecute is true than when UseShellExecute is false. When UseShellExecute is true, the WorkingDirectory property specifies the location of the executable. If WorkingDirectory is an empty string, the current directory is understood to contain the executable.

When UseShellExecute is false, the WorkingDirectory property is not used to find the executable. Instead, it is used by the process that is started and has meaning only within the context of the new process.[/tt]
unquote
 
Thanks tsuji, that works. I needed to put the full path of the exeternal app as the filename since the external app does not run from the same directory of the class.

Code:
[green]//lpEncryptPassword.StartInfo.WorkingDirectory = @"f:\dot-net\c#\PWE\2.0\PWE";[/green]
lpEncryptPassword.StartInfo.FileName = @"f:\dot-net\c#\PWE\2.0\PWE\EncryptPassword.exe";

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top