-1

I'm having an issue while running ffmpeg from VBS as follows:

Cmd = "cmd.exe /K " & Chr(34) & """C:\Users\admin\Documents\ffmpeg\bin\ffmpeg.exe""" & Chr(34) & " -i " & Chr(34) & """C:\Users\admin\Documents\TestFiles\3000012936-TXMHD.mxf""" & Chr(34) & " -vcodec copy -acodec copy " & Chr(34) & """C:\Users\admin\Documents\TestFiles\3000012936-TXMHD.mp4""" & Chr(34) '& " 2> " & Chr(34) & "LogFile.txt" & Chr(34)

objShell.Run Cmd, 10, True

I'm getting error: The system cannot find the path specified

The path for the input/output files is correct. I can guess this seems to be an escape sequence issue. Can some please point out.

user726720
  • 1,127
  • 7
  • 25
  • 59
  • Why are you adding `Chr(34)` when you already escape the double quotes using `""`? Get rid of the `" & Chr(34) & "` and it will work. – user692942 Sep 15 '20 at 10:25

2 Answers2

1

Try this;

Cmd = "cmd.exe /K ""C:\Users\admin\Documents\ffmpeg\bin\ffmpeg.exe"" -i ""C:\Users\admin\Documents\TestFiles\3000012936-TXMHD.mxf"" -vcodec copy -acodec copy ""C:\Users\admin\Documents\TestFiles\3000012936-TXMHD.mp4"" 2> LogFile.txt"

Will equate to the command line;

cmd.exe /K "C:\Users\admin\Documents\ffmpeg\bin\ffmpeg.exe" -i "C:\Users\admin\Documents\TestFiles\3000012936-TXMHD.mxf" -vcodec copy -acodec copy "C:\Users\admin\Documents\TestFiles\3000012936-TXMHD.mp4" 2> LogFile.txt

The issue was caused by adding Chr(34) (a literal double quote) to the string when the double quotes had already been escaped by "" (doubling them).


Useful Links

user692942
  • 16,398
  • 7
  • 76
  • 175
  • I have tried this, nothing happens it doesn't trigger the ffmpeg.I have also put the ffmpeg path in the environment variables Path. – user726720 Sep 15 '20 at 11:00
  • 1
    @user726720 does it fix the initial error? You should be able to run that generated command line in `cmd.exe` and see what happens. I'm also assuming you have the other code that takes the `Cmd` variable and runs the command line (as you didn't include that in the original post but you still managed to suggest it errored). – user692942 Sep 15 '20 at 11:41
  • 'objShell.Run Cmd, 10, True' this is part of my code, sorry i didn't include it in there. I will modify the question. I tried directly from the cmd it works just by omitting the cmd.exe from the above command. If i put cmd.exe and run from command prompt it doesnt work. Am I missing something. – user726720 Sep 15 '20 at 14:46
  • I got it working by removing the cmd.exe from the command and directly using ffmpeg as follows: `Cmd = "cmd.exe /k ffmpeg.exe -i ""C:\Users\admin\Documents\TestFiles\3000012936-TXMHD.mxf"" -vcodec copy -acodec copy ""C:\Users\admin\Documents\TestFiles\3000012936-TXMHD.mp4"""` Now the issue is how can i pipe this output to a text file. I tried using `2> LogFile.txt` but it doesn't seem to work. – user726720 Sep 15 '20 at 15:27
  • @user726720 you might find this helpful - [cmd.exe redirection operators order and position](https://stackoverflow.com/q/25559389) – user692942 Sep 15 '20 at 15:56
0

You can quote your variables easily with this function DblQuote(str)

strcmd = "Cmd /K " & DblQuote("C:\Users\admin\Documents\ffmpeg\bin\ffmpeg.exe") & " -i "& DblQuote("C:\Users\admin\Documents\TestFiles\3000012936-TXMHD.mxf") &" -vcodec copy -acodec copy "& DblQuote("C:\Users\admin\Documents\TestFiles\3000012936-TXMHD.mp4") &" 2> LogFile.txt"
wscript.echo strcmd
'---------------------------------------
Function DblQuote(Str)
    DblQuote = Chr(34) & Str & Chr(34)
End Function
'---------------------------------------
user692942
  • 16,398
  • 7
  • 76
  • 175
Hackoo
  • 18,337
  • 3
  • 40
  • 70
  • 1
    Why is that easy? It's easier IMO, to just double the quotes and avoid any unnecessary concatenation altogether. – user692942 Sep 15 '20 at 12:23