Why Run> doesn't work like Start, Run?

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
fightcancer
Macro Veteran
Posts: 166
Joined: Fri Apr 15, 2005 8:32 am

Why Run> doesn't work like Start, Run?

Post by fightcancer » Tue Jun 16, 2020 8:57 pm

Why doesn't the Run> command do what Start | Run would do? Using Start | Run works, but Run> does not.

In the code below, the macro builds this string and then runs that string, i.e.:
Run>D:\ffmpeg\bin\ffmpeg -ss 591 -i in.mp4 -t 90 -c copy out.mp4

The command prompt flickers on and off, but I can't tell what, if anything, it did. The result is nothing. I couldn't get ExecuteFile to function as Start | Run either.

When I paste this string into Start | Run, it works as intended in Windows 10.
D:\ffmpeg\bin\ffmpeg -ss 591 -i in.mp4 -t 90 -c copy out.mp4

Code: Select all

/* Run ffmpeg to shorten a video.
ffmpeg -ss 591 -i in.mp4 -t 213 -c copy out.mp4  (is the same as the line below)
ffmpeg -ss 591 -i in.mp4 -to 804 -c copy out.mp4

More notes here:
https://superuser.com/questions/377343/cut-part-from-video-file-from-start-position-to-end-position-with-ffmpeg
*/
Let>GeneralWait=0.1
Let>ffmpegPath=D:\ffmpeg\bin\ffmpeg
Let>StartTime=591
Let>NewVideoDuration=90
  Wait>GeneralWait
  Wait>GeneralWait
  Wait>GeneralWait

Let>strFFmpeg=ffmpegPath
Concat>strFFmpeg, -ss
//Let>strFFmpeg= -ss
Concat>strFFmpeg,%space%
Concat>strFFmpeg,%StartTime%
Concat>strFFmpeg, -i in.mp4 -t
Concat>strFFmpeg,%space%
Concat>strFFmpeg,%NewVideoDuration%
Concat>strFFmpeg, -c copy out.mp4

Run>strFFmpeg
//ExecuteFile>%ffmpegPath%,%strFFmpeg%
//Msg>RP_RESULT
Msg>strFFmpeg

Label>MacroEnd
Why is the richest nation ever 2nd to last in childhood poverty (among developed nations), 49th in literacy, 37th in general health, 41st in infant mortality?

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 679
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Why Run> doesn't work like Start, Run?

Post by Dorian (MJT support) » Wed Jun 17, 2020 12:01 pm

The problem isn't RunProgram, it's the strFFmpeg you're creating. There's a few things missing.

Let's get back to basics. Here's an example of some working RunProgram ffmpeg code which creates a 3 second clip.

Code: Select all

RunProgram>CMD /c c:\ffmpeg\bin\ffmpeg.exe -ss 00:00:0 -i c:\ffmpeg\bin\fs18.mp4 -t 00:00:03 c:\ffmpeg\bin\out6.mp4
Notice it contains CMD /c and all the file paths.

The string you're creating looks more like this :

Code: Select all

D:\ffmpeg\bin\ffmpeg -ss 591 -i in.mp4 -t 90 -c copy out.mp4
..which of course will work in Run>CMD if we've already changed to the ffmpeg directory.

You're then running this from Macro Scheduler:

Code: Select all

Run>D:\ffmpeg\bin\ffmpeg -ss 591 -i in.mp4 -t 90 -c copy out.mp4
We want something like this :

Code: Select all

RunProgram>CMD /c d:\ffmpeg\bin\ffmpeg.exe -ss 591 -i d:\ffmpeg\bin\in.mp4 -to 804 -c copy d:\ffmpeg\bin\out2.mp4
So let's adapt it a little, from your script. I have tested this and it works :

Code: Select all

Let>GeneralWait=0.1
Let>ffmpegPath=D:\ffmpeg\bin\ffmpeg

Let>StartTime=591
Let>NewVideoDuration=90
Wait>GeneralWait
Wait>GeneralWait
Wait>GeneralWait

Let>strFFmpeg=CMD /C
Concat>strFFmpeg, %ffmpegPath%
Concat>strFFmpeg, -ss
Concat>strFFmpeg,%space%
Concat>strFFmpeg,%StartTime%
Concat>strFFmpeg, -i d:\ffmpeg\bin\in.mp4 -t
Concat>strFFmpeg,%space%
Concat>strFFmpeg,%NewVideoDuration%
Concat>strFFmpeg, -c copy d:\ffmpeg\bin\out4.mp4

Run>strFFmpeg
And this works too, without all the Concats :

Code: Select all

Let>StartTime=591
Let>NewVideoDuration=90
Let>ffmpegPath=D:\ffmpeg\bin\ffmpeg
Let>strFFmpeg=CMD /C %ffmpegPath% -ss %StartTime% -i d:\ffmpeg\bin\in.mp4 -t %NewVideoDuration% -c copy d:\ffmpeg\bin\out5.mp4
Run>strFFmpeg
Yes, we have a Custom Scripting Service. Message me or go here

fightcancer
Macro Veteran
Posts: 166
Joined: Fri Apr 15, 2005 8:32 am

Re: Why Run> doesn't work like Start, Run?

Post by fightcancer » Wed Jun 17, 2020 3:18 pm

That was impressive. Thanks for the help!

I didn't realize I needed to run it through CMD. I don't understand why the "/c" parameter is necessary. Just curious.

Also, thanks for showing me how I could use the longer string to avoid all the Concat statements, i.e. Let>strFFmpeg=CMD /C %ffmpegPath% -ss %StartTime% -i d:\ffmpeg\bin\in.mp4 -t %NewVideoDuration% -c copy d:\ffmpeg\bin\out5.mp4
Why is the richest nation ever 2nd to last in childhood poverty (among developed nations), 49th in literacy, 37th in general health, 41st in infant mortality?

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 679
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Why Run> doesn't work like Start, Run?

Post by Dorian (MJT support) » Thu Jun 18, 2020 9:54 am

Here you go. I usually use /C when I want the window to close afterwards, and /K if I want it to stay open. This is useful if things aren't going as expected.
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\>cmd /?
Starts a new instance of the Windows XP command interpreter

CMD [/A | /U] [/Q] [/D] [/E:ON | /E:OFF] [/F:ON | /F:OFF] [/V:ON | /V:OFF]
[[/S] [/C | /K] string]

/C Carries out the command specified by string and then terminates
/K Carries out the command specified by string but remains
/S Modifies the treatment of string after /C or /K (see below)
/Q Turns echo off
/D Disable execution of AutoRun commands from registry (see below)
/A Causes the output of internal commands to a pipe or file to be ANSI
/U Causes the output of internal commands to a pipe or file to be
Unicode
/T:fg Sets the foreground/background colors (see COLOR /? for more info)
/E:ON Enable command extensions (see below)
/E:OFF Disable command extensions (see below)
/F:ON Enable file and directory name completion characters (see below)
/F:OFF Disable file and directory name completion characters (see below)
/V:ON Enable delayed environment variable expansion using ! as the
delimiter. For example, /V:ON would allow !var! to expand the
variable var at execution time. The var syntax expands variables
at input time, which is quite a different thing when inside of a FOR
loop.
/V:OFF Disable delayed environment expansion.
Having played around with my original ffmpeg sample, this also works :

Code: Select all

RunProgram>c:\ffmpeg\bin\ffmpeg.exe.... -ss 00:00:0 -i c:\ffmpeg\bin\fs18.mp4 -t 00:00:03 c:\ffmpeg\bin\out668.mp4
Yes, we have a Custom Scripting Service. Message me or go here

fightcancer
Macro Veteran
Posts: 166
Joined: Fri Apr 15, 2005 8:32 am

Re: Why Run> doesn't work like Start, Run?

Post by fightcancer » Sat Jun 20, 2020 8:03 pm

Thanks again!
Why is the richest nation ever 2nd to last in childhood poverty (among developed nations), 49th in literacy, 37th in general health, 41st in infant mortality?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts