So we need to execute a exe in our .net API, and this exe is built at the same time as the API itself in our pipelines.
The exe is present in the exact same directory as our .NET API exe and ddl files.
I used the below code to try and trigger the exe:
var process = new System.Diagnostics.Process();
process.StartInfo.FileName = "customProgram.exe";
process.StartInfo.Arguments = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
process.Start();
process.WaitForExit();
This throws an error:
An error occurred trying to start process 'customProgram.exe' with working directory '/app'. No such file or directory
Try to specify the full path to the file.
For example like here:
Process.Start(#"C:\Program Files\Google\Chrome\Application\chrome");
Related
I have a SQL Job that's running on a DB Server and on one of the steps it calls an application server to run an exe "cmd Exec step type"
the exe application "C#" is invoked properly and does all its intended tasks, as a final step it runs cmd.exe to merge couple of files.
** When running the exe application manually, it's working as intended, but when invoking through SQL Job it's returning the below error:
Error in MergeFiles() Method : System.ComponentModel.Win32Exception (0x80004005): The directory name is invalid
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
at _700CreditBillingScheduler.Billing700C.MergeFilesInPath()
Worth saying everything is running on E:\ drive
Here is my code:
string filePath = "E:\\HomeFolder\\ApplicationFolder"; // where merged file will be created
string sourcePath = "E:\\HomeFolder\\ApplicationFolder\\Transaction.Indiv.Files\\*.csv"; // to be merged
string commandLine = String.Format("/c copy /b {0} {1}", sourcePath, "mergedFileName");
var cmd = new ProcessStartInfo("cmd.exe", commandLine);
cmd.WorkingDirectory = filePath;
cmd.UseShellExecute = false;
Process.Start(cmd);
Try to remove the line where you specify the working dir ?
I found the issue, it has to do with the UNC path.
The command was trying to merge the files on DB Server using the UNC path of the file, and UNC isn't supported through cmd.exe, so instead it ran on DB Server where the directory doesn't exist.
I switched to merge the files on application server using the C# application itself.
ProcessStartInfo psi = new ProcessStartInfo("java.exe", " -jar \"C:\\craFVUsubsreg-lite_APY.jar\"");
psi.UseShellExecute = false;
Process p = new Process();
p.StartInfo = psi;
p.Start();
I want to invoke the utility tool, which is of java.jar file within the "c#" [mvc] application and it is work fine when i run the application through code. However after i published the application and then i try to invoke the same jar file it is not responding or i can say it is not working.
Above is the process code which i'm using to invoke the jar file. Even the user permission i have setted to full control mode.
Kindly guide me, where i am wrong, or is their any way to directly invoke the java.jar file without converting to java.exe.
So here's my end goal. Steam allows you to add other installed games to your library but only if it's a .exe file it's pointed at to start running.
I just installed Arena and Daggerfall and they both run via DOSBox which is launched from a .bat file. So I decided to turn it into a .exe by writing my own. So far I've got the code written. When I just run the .bat file, it opens everything fine, however, when I try running it from my code, the .bat file executes but with errors. Here is my code below:
if (File.Exists("D:\\Bethesda Softworks\\Arena\\Arena (Full Screen).bat"))
{
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("cmd.exe", "/c" + "\"D:\\Bethesda Softworks\\Arena\\Arena (Full Screen).bat\"");
psi.RedirectStandardOutput = true;
psi.UseShellExecute = false;
System.Diagnostics.Process proc;
proc = System.Diagnostics.Process.Start(psi);
}
And the error I'm getting is this:
"The system cannot find the path specified. 'dosbox.exe' is not recognized as an internal or external command, operable program or batch file.
I'm not sure if this is an issue because of how dosbox is called from the Batch file or how the .exe ends up running the batch file. Either way, I'd rather fix this in the code rather than by making alterations to the .bat file itself.
Any help is greatly appreciated!!
Try setting ProcessStartInfo.WorkingDirectory
psi.WorkingDirectory = "D:\\Bethesda Softworks\\Arena";
i'm starting a child application from my main process with the following code:
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = DestinationNameEXE;
startInfo.WorkingDirectory = Toolbox.AssemblyDirectory;
startInfo.UseShellExecute = true;
startInfo.Arguments =
binParameter + #" """ + _BINPath + #" """
+ tmpParameter + #" """ + binFolder_ForExtration + #" """;
Process.Start(startInfo);
before i do this i check if the process has write rights in the binFolder_ForExtration and _BInPath with following code (source) and a simple write file check:
try
{
using (File.Create(tmpfile)) { }
File.Delete(tmpfile);
createFilesAllow = true;
}
catch
{
createFilesAllow = false;
}
in the main process i can write & create files. also the function HasWritePermissionOnDir returns true.
in the new process i'm doing the same test, but in this case i got from HasWritePermissionOnDir true, but if i try to create a file, i got an exception. the new process has the rights to change existing files.
how can this be? what i'm doing wrong?
how can the new process have less rights then the first process?
i don't change the user context.
i' have also tested to start the process with ProcessAsUser.Launch (source) but without any change. the new process dond't have the right to create new files in the given folder.
if i start the process with elevated rights:
startInfo.Verb = "runas";
everything works finde. the new process can write, create and change files in the given folder.
thx for any help
Update:
i'm testing on a windows 7 x86
the main process is compiled with target x86 and .Net 4.5. its a dll called from a vb6 application
the user i'm testing with has admin rights (but it's not the user administrator). the main process is started with normal rights settings (not elevated rights)
the new process is compiled with target any CPU and .Net 4.5.
since i require access to Process.GetProcesses in the new process it should be compiled as any CPU to be used on x86 and x64 systems (as far as i know)
currently all folder tests and occured errors happend in the folder *c:\Program Files (x86)\appname\BIN*. in the code i'm using full path and test the correctness of the path with direcotry.exist() bevore any execution.
I have this very simple program
Process process = new Process();
process.StartInfo.FileName = #"psexec";
process.Start();
But when I run it the debug says "The system cannot find the file specified"
If I have the same program and change "psexec" by "Notepad", it works and opens notepad.
Process process = new Process();
process.StartInfo.FileName = #"notepad";
process.Start();
This is weird because I have my psexec in the System32 and if run "psexec" using Windows-Run, it works.
Thank you in advance for any help.
Update: I specify the full path #="C:\Windows\System32\PSexec.exe" and It doesnt work. But If I move Psexec to, as example #"D:\psexec.exe" it works!!
Why coud this happen?
Running programs from c:\windows\system32 is troublesome on a 64-bit operating system. The workaround is Project + Properties, Build tab, change Platform target to AnyCPU. Or to copy the file also to c:\windows\syswow64.
Or to just not put it in the Windows directory, it is not an operating system specific file that belongs there. The appropriate place is the same directory as your EXE.
You can learn more about the File System Redirector in this MSDN article.
try specify the full path of 'psexec'
there is any property 'WorkingDirectory', which might help.