Sign in to follow this  
Followers 0
dynamitemedia

Run, Runwait or @ComSpec piping output using "|"

20 posts in this topic

I have searched and i think issue comes down to not knowing the terminology of what i am looking for...

i came from doing bat files etc  and you can do stuff like this

ffmpeg -i -f flv movie.flv | yamdi.exe command1 command 2

 how is this done in Autoit?

I need to pipe ffmpeg to another program as shown above  

ffmpeg ------>  Yamdi

i am still having so many issues with the double quotes and single quotes lol

thanks i just cant seem to find this issue on the forums

Share this post


Link to post
Share on other sites



I have found this but i can not seem to get it working with my example

http://www.catonrug.net/2013/06/autoit-runwait-command-with-pipe.html

RunWait(@ComSpec & ' /c ' & 'echo 1 | "C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client\vpncli.exe" connect profile_name & pause', '', @SW_SHOW)

I have tried several ways including this:

RunWait(@ComSpec & ' /c ' & '  ffmpeg -i -f flv movie.flv | "yamdi.exe" command1 command 2', @ScriptDir, @SW_SHOW)

as well as

ShellExecuteWait(@ScriptDir & "\ffmpeg.exe", $ffmpeg_args | @ScriptDir & "\yamdi.exe", $yamdi_args )

with no luck   any ideas what i could be doing wrong... the args are just for saveing a video and yamdi adds he metafata...   works from command line

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

You can try to specify the full path path for each program and file :

RunWait(@ComSpec & ' /c  "c:\directory of ffmpeg\ffmpeg.exe" -i -f flv "c:\full\path\of\the\movie\movie.flv" | "c:\directory of yamdi\yamdi.exe" command1 command 2', @ScriptDir, @SW_SHOW)
Edited by jguinch

Share this post


Link to post
Share on other sites

tried this but as soon as it see the "|"  it just closes...  without it ffmpeg opens  then i add "|" it closes

tried with a few different programs and same thing....  i tried  ascii code & Chr(124) &  all a no go

can you show me a test with any programs you had working?   i tried pumping to VLC as well all with no luck  

Share this post


Link to post
Share on other sites

ok so if i only need 2 commands it would look like this?
 

; run commands concurrent
$iPID1 = Run(@ComSpec & " /C " & $sCmd1, "", @SW_HIDE, 9) ; $STDIN_CHILD(1) + $STDERR_MERGED(8)
$iPID2 = Run(@ComSpec & " /C " & $sCmd2, "", @SW_HIDE, 9) ; $STDIN_CHILD(1) + $STDERR_MERGED(8)

; pipe output of first command as input to second command
While Sleep(10)
    $sTmp = StdoutRead($iPID1, False, True)
    If @error Then ExitLoop StdinWrite($iPID2)
    StdinWrite($iPID2, $sTmp)
WEnd


; display output of third command
MsgBox(Default, Default, StdoutRead($iPID2), 0)

and then here goes like this?

" & $sCmd1, " COMMANDS HERE",

 

Share this post


Link to post
Share on other sites

tried this but as soon as it see the "|"  it just closes...  without it ffmpeg opens  then i add "|" it closes

tried with a few different programs and same thing....  i tried  ascii code & Chr(124) &  all a no go

...can you show me a test with any programs you had working?   i tried pumping to VLC as well all with no luck  

In experiencing issues, it seems you are blaming what is not at fault. Piping seems to work fine. Using Chr(124) seems quite unnecessary.

You may still need to escape certain characters passed to CMD under certain conditions. Like this example where a For loop does not like a pipe character unless it is escaped with a caret (^).

; Run cmd with /q = Echo off, /k Remain open. Pipe dir output to sort.
Run("cmd /q /k for /f %A in ('dir /b ^| sort') do echo %A")

.

Piping FFMPEG to VLC can be done. An example that I tested as working on Windows 7 X64 with VLC X86 ver. 2.1.5 installed and with FFMPEG ver. N-52941-g13cb6ed static built on 2013-05-09 in a folder that is in %path%. I added some extra double quotes which do not cause any issue.

; Select a FLV media file. Option 1 = File must exist.
$input_flv = FileOpenDialog('Select FLV media file', EnvGet('SystemDrive'), 'Flash media file (*.flv)', 1)
If @error Then Exit

; Set full path to vlc.exe.
$vlc_fullpath = EnvGet('ProgramFiles') & '\VideoLAN\VLC\vlc.exe'
If Not FileExists($vlc_fullpath) And @OSArch <> 'X86' Then
    $vlc_fullpath = EnvGet('ProgramFiles(x86)') & '\VideoLAN\VLC\vlc.exe'
EndIf

; Last attempt to find vlc.exe if not found already.
If Not FileExists($vlc_fullpath) Then
    ; Select location to vlc.exe. Option 1 = File must exist.
    $vlc_fullpath = FileOpenDialog('Find vlc.exe', EnvGet('SystemDrive'), 'Executable file (*.exe)', 1, 'vlc.exe')
    If @error Then Exit
EndIf

; Run the command. The command expects ffmpeg to be in the path.
$command = 'cmd /k ffmpeg -i "' & $input_flv & '" -c:v "copy" -c:a "copy" -f "flv" pipe:1 | "' & $vlc_fullpath & '" -'
Run($command)
If @error Then MsgBox(0x40030, @ScriptName, 'This command failed to run.' & @CRLF & @CRLF & $command)
;

As for yamdi, I do not know why it does not like the pipe from ffmpeg. Perhaps a later build of ffmpeg may help. Perhaps yambi is stdin incompetent. Perhaps my lack of experience with yambi is failing me. I do not have the answer with ffmpeg | yambi though perhaps I have helped with what it is not.

1 person likes this

Share this post


Link to post
Share on other sites

ok so this actually using a command line... I like this too for sure!  So there is no way to actually doing the "|" pipe in the autoscript code then?

also been having some issues with having ffmpeg else where but will play with that...

 

 

i have tried a LOT of combos on the ffmpeg location and wont read it even full path...    i cant have ffmpeg in the current Directory

 

Share this post


Link to post
Share on other sites

I use the static builds of FFMPEG so dependencies hopefully are not an issue. No issues so far for me to report. I just updated FFMPEG and I am still getting failure piping to YAMDI. I downloaded ffmpeg-20141110-git-064a237-win32-static.7z from this page. I have a custom folder that is permanently assigned to %path% of where I put all the files like ffmpeg.exe so it is easy to maintain.

Testing with variations of like:

Run('cmd /k ffmpeg -i "movie 1.flv" -c:v copy -c:a copy -f flv pipe:1 | yamdi -i - -o "movie 2.flv" -t nul.flv', 'c:\temp\test')

of where "movie 1.flv" exists in the working directory of "c:temptest".

Since a temp file seems to be needed if you stdin to YAMDI, then perhaps piping has little advantage compared to doing the task with separate 2 commands. All these tools may not follow a template so knowing how to use each one sometimes takes some skill with some luck.

So 2 commands like below. It does not use copy parameters so does a convert with defaults. You may need to adjust the filenames and working directory for testing.

Run('cmd /k "ffmpeg -i "movie 1.flv" -f flv "tmp.flv" && yamdi -i "tmp.flv" -o "movie 2.flv" && del "tmp.flv""', 'c:\temp\test')

So the sequence is that FFMPEG converts "movie 1.flv" to tmp.flv. YAMDI reads tmp.flv and saves to "movie 2.flv" and then tmp.flv is deleted.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

well the issue i am having is that is folder where ffmpeg and ymdi are/will be located... it is NOT in same directory of the script

is that what this means?

'c:temptest')

this is the errors i keep getting 

'C:Documents' is not recognized as an internal or external command,
operable program or batch file.
 
that is from the full path of the programs,   i wish i could wrap my head around these quotes!!
Edited by dynamitemedia

Share this post


Link to post
Share on other sites

yamdi.exe is one file so if you have it in the working directory or %path% then it should be OK to access it by just its filename. Same can be said for the static build of ffmpeg.exe. Both files mention should have no other file dependencies.

The working directory parameter of Run() that you show in red is the working directory that cmd will inherit. So if the command prompt window showed the prompt initially, it would be like C:temptest>. Thus, the commands of ffmpeg or yamdi look for the filenames in C:temptest. If the filenames are not found in the current working directory as being C:temptest in this case, then the paths in the %path% variable will be searched. If you are unsure that i.e. ffmpeg.exe is in path then try entering where ffmpeg.exe into a command prompt and see if it echos the path of where it exists.

You can use absolute paths for yamdi.exe or ffmpeg.exe if you want. I am not sure how you want the paths to work (relative or absolute) so cannot give a precise answer.

Share this post


Link to post
Share on other sites

im a very new programmer and understand about half of that please forgive me...  i have only used autoit like 4 days now so some is still confusing me but i am trying

for example my ffmpeg is currently like this

$ffmpeg = @ScriptDir & "\bin\ffmpeg.exe"

when i try using it say like this:

$ffmpegRecorder = $ffmpeg & ' -re -rtbufsize 100000k -i - -c:v "copy" -c:a "copy" -f "flv" testing447777.flv'

it wont work cause it needs to be like this with the double quotes around it

$ffmpegRecorder = "C:\Documents and Settings\Desktop\appTesttig\bin\ffmpeg.exe"  ' -re -rtbufsize 100000k -i - -c:v "copy" -c:a "copy" -f "flv" testing447777.flv'

i can verify it works with full path and double quotes,  getting them however , i am totally lost again

i have spent 12+ hours today messing with these quotes they are so confusing on how to make them work and seems each case is different

Share this post


Link to post
Share on other sites

Ahh, quoting issues on Windows 2000/XP.

Your commands with double quotes around $ffmpeg (as it contains whitespace) would be like this:

$ffmpeg = @ScriptDir & "\bin\ffmpeg.exe"

$ffmpegRecorder = '"' & $ffmpeg & '" -re -rtbufsize 100000k -i - -c:v "copy" -c:a "copy" -f "flv" testing447777.flv'
MsgBox(0, 'View $ffmpegRecorder', $ffmpegRecorder)

$ffmpegRecorder = '"C:\Documents and Settings\Desktop\appTesttig\bin\ffmpeg.exe" -re -rtbufsize 100000k -i - -c:v "copy" -c:a "copy" -f "flv" testing447777.flv'
MsgBox(0, 'View $ffmpegRecorder', $ffmpegRecorder)

; Use single quote to wrap double quotes or the reverse usage or just double up the quotes.
$var = '"' & "'" & '""' & "''" & """" & ''''
MsgBox(0, 'View $var', $var)

Share this post


Link to post
Share on other sites

 

Nice thanks!!  But now im  back to  stupid quote issues! lol

so now i have this and i am back to the

 
same code you gave me above

but trying using it like this

Run(@ComSpec & " /K " & $ffmpegRecorderr & "|" & $yamdi, @ScriptDir, @SW_SHOW)

again this will work hard coded paths but when i try and use the "variables" as we did above to get the paths its gives errors.....   when you show me the quotes can you explain using this example   also i do not get why there is only 1 "%" in yamdi....

I found this code here :https://www.autoitscript.com/wiki/Snippets_(_CMD_)

; Run program in CMD.exe window with changed title.
 
Func _RunCMD($sTitle, $sCommand) ; Returns PID of Run.
    Return Run(@ComSpec & " /K title " & $sTitle & "|" & $sCommand)
EndFunc ;==>_RunCMD

 

 

example this will work coded like this

$ffmpegRecorder = '"C:\Documents and Settings\settop\Desktop\ffmpeg.exe" -re -rtbufsize 100000k -i - -c:v "copy" -c:a "copy" -f "flv" testing44.flv'

but if i try to put full path to say VLC or Yamdi or another FFMPEG or ffplay  it will not play well

if i put something like this it will work  with full path to FFmpeg after the "|"   

$vlc = 'vlc.exe .....'
$ffmpegRecorder = '"C:\Documents and Settings\settop\Desktop\ffmpeg.exe" -re -rtbufsize 100000k -i - -c:v "copy" -c:a "copy" -f "flv" testing44.flv'

Run(@ComSpec & " /K " & $vlc & "|" & $ffmpegRecorder, @ScriptDir, @SW_SHOW)

BUT it will not let me put the full path to VLC or any other full path to ANY program before the "|"

i just get this error

 

 'C:Documents' is not recognized as an internal or external command,

operable program or batch file

 

1 person likes this

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

Sounds like your quotes are off ;)

or else it wouldn't cut off at the space.

Edited by MikahS
1 person likes this

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

Sounds like your quotes are off ;)

or else it wouldn't cut off at the space.

 

do you think the quote is off in setting the variable or is it in the Run command? im going in circles i change one thing it breaks another! lol

Share this post


Link to post
Share on other sites

i think i am seeing or finding the issue now

this is error i just got:

 "C:\\Documents and Settings\\settop\\Desktop\\bin\\HLS-ffmpeg.exe'

do what it is doing is adding extra "" to it

do you think the quote is off in setting the variable or is it in the Run command? im going in circles i change one thing it breaks another! lol

Got it finally thanks everyone... will post the full working later in case it can help someone else...

my sample i am using now is using VLC and not Yamdi so i need to rewrite it now know i can get the paths to the exe files working... 

 

Share this post


Link to post
Share on other sites

 

Ahh, quoting issues on Windows 2000/XP.

 

If i code this on XP will these quoting issues mess up on another OS/?

Share this post


Link to post
Share on other sites

example this will work coded like this

$ffmpegRecorder = '"C:\Documents and Settings\settop\Desktop\ffmpeg.exe" -re -rtbufsize 100000k -i - -c:v "copy" -c:a "copy" -f "flv" testing44.flv'

but if i try to put full path to say VLC or Yamdi or another FFMPEG or ffplay  it will not play well

if i put something like this it will work  with full path to FFmpeg after the "|"   

$vlc = 'vlc.exe .....'
$ffmpegRecorder = '"C:\Documents and Settings\settop\Desktop\ffmpeg.exe" -re -rtbufsize 100000k -i - -c:v "copy" -c:a "copy" -f "flv" testing44.flv'

Run(@ComSpec & " /K " & $vlc & "|" & $ffmpegRecorder, @ScriptDir, @SW_SHOW)

BUT it will not let me put the full path to VLC or any other full path to ANY program before the "|"

i just get this error

In this case, your command starts with a double quote and you have more then 1 pair of quotes. CMD will strip the outer double quotes under this condition.

A not so good example as I know wordpad will not redirect anything, though, it shows the behavior with the quotes:

Run('cmd /k "%ProgramFiles%\Windows NT\Accessories\wordpad.exe" > "test file.txt"')

See above how the command starts with a double quote and that more then 1 pair of double quotes exist in the command as "test file.txt" has whitespace in it. CMD will see this and will strip the outer double quotes. So the command run is like this where %programfiles% is not expanded yet but imagine it has expanded with the whitespace in the files path showing:

%ProgramFiles%\Windows NT\Accessories\wordpad.exe" > "test file.txt

It may generate an error such as:

'C:\Program' is not recognized as an internal or external command, operable program or batch file.

which is breaking at the 1st instance of whitespace in the command. The command has inadequate quoting due to the behavior of CMD.

If you look at CMD /? to see the reason for this behavior, you may see this.

If /C or /K is specified, then the remainder of the command line after
the switch is processed as a command line, where the following logic is
used to process quote (") characters:

    1.  If all of the following conditions are met, then quote character
        on the command line are preserved:

        - no /S switch
        - exactly two quote characters
        - no special characters between the two quote characters,
          where special is one of: &<>()@^|
        - there are one or more whitespace characters between the
          two quote characters
        - the string between the two quote characters is the name
          of an executable file.

    2.  Otherwise, old behavior is to see if the first character is
        a quote character and if so, strip the leading character and
        remove the last quote character on the command line, preserving
        any text after the last quote character.

The explanation of above is that the command uses /k. In condition 1, exactly two quote characters has not been met with the command. So condition 2 applies, thus it mentions about stripping quotes as being the 1st character and the last character. To counter this behavior, you insert additional quotes that can be stripped so the original command is left intact.

So with this information mentioned, the command is changed to:

Run('cmd /k ""%ProgramFiles%\Windows NT\Accessories\wordpad.exe" > "test file.txt""')

Now the outer quotes will be stripped and the command processed will be this:

"%ProgramFiles%\Windows NT\Accessories\wordpad.exe" > "test file.txt"

and so no error should happen. At this point, you should probably be feeling better knowing how to resolve the behavior.

i think i am seeing or finding the issue now

this is error i just got:

 "C:\\Documents and Settings\\settop\\Desktop\\bin\\HLS-ffmpeg.exe'

do what it is doing is adding extra "" to it

Got it finally thanks everyone... will post the full working later in case it can help someone else...

my sample i am using now is using VLC and not Yamdi so i need to rewrite it now know i can get the paths to the exe files working...

A pair of backslashs i.e. separating segments of a path is interpreted the same as a single backslash by CMD i.e. . This is because within a path is meaningless as no path segment exists between the backslashs.

Example of many backslashs:

Run('cmd /k ""%ProgramFiles%\\\\\\\\\\Windows NT\Accessories\wordpad.exe" > "test file.txt""')

All of those repetitive backslashs will be interpreted as 1 i.e. = .

If i code this on XP will these quoting issues mess up on another OS/?

Probably not. My reference was to recognize your OS by your reference to "Documents and Settings". So long as you quote well, then issues hopefully will not happen.

 

1 person likes this

Share this post


Link to post
Share on other sites

Thanks for taking your time to explain, now i can go back for reference...  outside that using Autoit has been a pleasure!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0