1

For some reason, I can't seem to launch and run a .cmd file with c#. An example of a line of the cmd file is:

"C:\Windows\system32\ffmpeg64.exe" -v verbose -y -i "S:\TEMP\A.ts" -c:v copy -c:a copy -ss 00:00:00.000 -t 2 "S:\TEMP\A_SHORT.ts"

I've tried several different ways to launch this file from within C#, such as (where curDirectory is for example "S:\TEMP")

Process p = Process.Start(curDirectory + "\\ffmpeg.cmd");

I've also tried

string path = curDirectory + "\\ffmpeg.cmd";
Process p = Process.Start("cmd.exe", @"/c " + path);  //I've also tried /k

But what happens is the cmd prompt will show up and say "C:\Windows\System32\ffmpeg64.exe" is not recognized ..." even though the file is there. What am I doing wrong?

6
  • If you run the .cmd file in question manually from the command prompt, it completes without error? Have you tried building a ProcessStartInfo object? Commented Nov 18, 2012 at 7:21
  • I should have mentioned that it runs perfectly fine when I double-click it AND when I run it from cmd. I have tried the ProcessStartInfo object as such ProcessStartInfo p = new ProcessStartInfo(path) but it also fails Commented Nov 18, 2012 at 7:32
  • are you running C# as admin? Commented Nov 18, 2012 at 7:34
  • check this out :stackoverflow.com/questions/361097/…\ Commented Nov 18, 2012 at 7:35
  • Tried running c# as admin, no go. I also tried a few more permutations of starting a process, some running cmd.exe with arguments "/c " + path, some directly calling the .cmd file. Everything keeps giving me the same "not recognized" message. I would really rather not have to read in the .cmd file, parse it, then run the arguments directly through ffmpeg64. Any other ideas? Commented Nov 18, 2012 at 9:07

1 Answer 1

0

If your system is running the Windows 6.1 kernel or later, System32 is actually comprised of other directories based on the application you're running (depending on whether it is a 32-bit or 64-bit application).

I assume that ffmpeg64.exe is a 64-bit application, and when you execute the .cmd file manually, it should default to a 64-bit command prompt - Also ensure that your application is targeting "x64" or "Any CPU". Alternatively, you could place a 32-bit version of ffmpeg in the WoW64 directory.

Also, I know you've stated in comments that you don't want to read the .cmd file and modify it, but you could compose your ProcessStartInfo with Environment.SystemDirectory instead of the hard-coded path.

As a last option, you could place the ffmpeg exe somewhere static (as you stated in the comments, in c:\ works), or just in your application's working directory.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.