I need to unzip a compressed file with the command line version of 7zip. This one liner should to the trick:
Process.Start("cmd", #"C:\Users\cw\Downloads\7za920\7za e C:\UPDATED.zip -oc:\");
I'm specifying the path to the 7zip command line executable, and telling it which file to unzip. If I copy and paste those arguments into my command line window, it will work. In C#, it will bring up a command line window, and nothing will happen. What gives?
Try:
Process.Start("cmd", #"/c C:\Users\cw\Downloads\7za920\7za e C:\UPDATED.zip -oc:\");
It's because you're running cmd.exe, and not 7za directly. You can do either of the two:
Process.Start(#"C:\users\...\7za", "e c:\updated.zip -oc:\");
or
Process.Start("cmd", #"/c c:\users\...\7za e c:\updated.zip -oc:\");
The /c flag tells cmd to run the arguments after starting.
Try
Process.Start(#"C:\Users\cw\Downloads\7za920\7za.exe", #"e C:\UPDATED.zip -oc:\");
Related
I would like to run a batch command in c# code.
I tried this code but it only pops up cmd but I want it to pop up cmd and displays "Hello World".
Process.Start("cmd", "echo Hello World");
Is it possible to do this?
Try this:
Process.Start("cmd", "/K echo Hello World");
(Note the "/K")
based on this reference for cmd.exe
What I got:
Process.Start("cmd.exe", "/K \"C:/Program Files/nodejs/node.exe\" \"C:/rc/rainingchain/app.js\"");
Even though I wrapped the filename with escaped ", it still displays the error:
'C:/Program' is not recognized as an internal or external command, operable program or batch file.
What is wrong?
You need to use two " for spaces in program path:
Process.Start("cmd.exe", "/K \"\"C:/Program Files/nodejs/node.exe\" \"C:/rc/rainingchain/app.js\"\"");
You code will be translated to
cmd.exe /K "C:/Program Files/nodejs/node.exe" "C:/rc/rainingchain/app.js"
cmd.exe will translate it to
C:/Program Files/nodejs/node.exe" "C:/rc/rainingchain/app.js
That's why it complain errors.
What you need is to enclose whole node.exe command with double quote again.
Process.Start("cmd.exe", "/K \"\"C:/Program Files/nodejs/node.exe\" \"C:/rc/rainingchain/app.js\"\""); so the node.exe command will be "C:/Program Files/nodejs/node.exe" "C:/rc/rainingchain/app.js"
BTW, why don't just call node.exe directly?
Process.Start("C:/Program Files/nodejs/node.exe", "C:/rc/rainingchain/app.js");
Process.Start("svn.exe", "log c:\\work\\lidac\\v1\\ -r {2014-09-01}:{2014-09-24} --xml > c:\\work\\commits.xml");
SVN is throwing an error over the >
Error resolving case of >
I am not sure why. The same command works if I type it directly into the command prompt. Any ideas?
You are passing that redirect output symbol to the svn.exe process. He doesn't understand what > c:\work\commits.xml means. If you want to do the redirect output to a file, you can either write code to get the output from the process object, or try something like:
Process.Start("cmd.exe", #"/C svn log C:\work\lidac\v1\ -r {2014-09-01}:{2014-09-24} --xml > c:\work\commits.xml");
When launching an application directly, the application is launched, but when launched through cmd - it's not.
For example:
Works:
Process.Start("firefox");
Doesn't work:
Process.Start(
new ProcessStartInfo
{
FileName = "cmd",
Arguments = "/k firefox"
});
I've tried setting UseShellExecute to true, but to no avail. I still get:
'firefox' is not recognized as an internal or external command,
operable program or batch file.
So, yes, I can specify the complete path. But is there a way to avoid that? Or in other words - what's the difference between the two that makes the second fail?
Haven't tested it but I guess you are probably looking for the start command:
Process.Start(
new ProcessStartInfo
{
FileName = "cmd",
Arguments = "/k start firefox"
});
As a tip, simply run "firefox" in a command prompt -> you'd get the same error message.
I'm trying to run a fortran executable with Process.Start and it is not working.
Process proc = new Process();
string args = "<C:\\file.in> C:\\file.out";
proc.StartInfo = new ProcessStartInfo(AppName, args);
proc.Start();
if I paste those arguments into a command window the application runs as expected. proc.Start() does not run as expected.
Any ideas how I can view what Start is actually passing as arguments? My gut feeling is that this is a quotes issue.
The executable launches and hangs, so I'm confident the AppName is getting passed in correctly, it looks like an argument problem.
I tried setting the WorkingDirectory to that of the input and output files as suggested in this question: process.start() arguments but that did not work.
Redirection with the < and > command line operators is a feature that's implemented by the command line processor. Which is cmd.exe. Use its /c argument to execute just a single command:
string args = "/c " + AppName + " < C:\\file.in > C:\\file.out";
proc.StartInfo = new ProcessStartInfo("cmd.exe", args);
proc.Start();
Your args string is exactly what is being passed as arguments to the executable. You can double check it reading your Process ProcessStartInfo.Arguments Property.
Something similar happened to me once, i.e., calling the executable from the command line worked and from code didn't, and it turned out that when called from the command line the executable was running on my PC's [C:] drive, and when called from code it was running on my PC's [E:] drive, which was full!
To check which directory your application is using to run the executable use the Directory.GetCurrentDirectory Method.