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?

Aeon2058
  • 527
  • 6
  • 22
  • If you run the .cmd file in question manually from the command prompt, it completes without error? Have you tried building a `ProcessStartInfo` object? – lukiffer Nov 18 '12 at 07: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 – Aeon2058 Nov 18 '12 at 07:32
  • are you running C# as admin? – Nahum Nov 18 '12 at 07:34
  • check this out :http://stackoverflow.com/questions/361097/c-sharp-service-cannot-execute-batch-file\ – Nahum Nov 18 '12 at 07: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? – Aeon2058 Nov 18 '12 at 09:07
  • Okay, I moved ffmpeg64 to C:\ and correspondingly changed the path in my .cmd file. Now it works. Why can't I run ffmpeg64.exe from C:\Windows\System32\ in C# but I can anywhere else? – Aeon2058 Nov 18 '12 at 09:29

1 Answers1

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.

lukiffer
  • 11,025
  • 8
  • 46
  • 70