get cmd output without file Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
pond_pop
Posts: 4
Joined: 04 Jun 2019, 08:01

get cmd output without file

02 Jul 2019, 06:26

i want to get output from ffmpeg without create or read file

Code: Select all

RunWait, C:\ffmpeg\ffmpeg -i img000001.jpg -i ref.jpg -lavfi "[0:v]scale=1706:960[vid1];[vid1][1:v]ssim" -f null –,,
" | clip" not work
User avatar
YoucefHam
Posts: 344
Joined: 24 Aug 2015, 12:56
Facebook: https://fb.me/YoucefHamDz
Google: [email protected]
GitHub: YoucefHam
Location: Algeria
Contact:

Re: get cmd output without file

02 Jul 2019, 07:03

try using the clipboard

Code: Select all

Run, %ComSpec% /c "ipconfig" | clip
MsgBox, % Clipboard
:wave: There is always more than one way to solve a problem. ;)
pond_pop
Posts: 4
Joined: 04 Jun 2019, 08:01

Re: get cmd output without file

02 Jul 2019, 11:00

YoucefHam wrote:
02 Jul 2019, 07:03
try using the clipboard

Code: Select all

Run, %ComSpec% /c "ipconfig" | clip
MsgBox, % Clipboard
clip not work
Image Broken Link for safety
User avatar
flyingDman
Posts: 860
Joined: 29 Sep 2013, 19:01

Re: get cmd output without file

02 Jul 2019, 12:55

Code: Select all

Run, %ComSpec% /c "ipconfig" | clip
ClipWait,1
MsgBox, % Clipboard
toralf
Posts: 792
Joined: 27 Apr 2014, 21:08
Location: Germany

Re: get cmd output without file

02 Jul 2019, 13:23

There is also stdouttovar() or if the process takes a little longer to finish stdoutstream(). Just search the forum.
ciao
toralf
garry
Posts: 2431
Joined: 22 Dec 2013, 12:50

Re: get cmd output without file  Topic is solved

02 Jul 2019, 13:53

toralf , thanks, tried with stdouttovar

Code: Select all

; RunWait, C:\ffmpeg\ffmpeg -i img000001.jpg -i ref.jpg -lavfi "[0:v]scale=1706:960[vid1];[vid1][1:v]ssim" -f null –,,
; ffmpeg is in the same folder for test

var1=ffmpeg -i test.jpg -i ref.jpg -lavfi "[0:v]scale=1706:960[vid1];[vid1][1:v]ssim" -f null
    C2:=""
    C2 := StdOutToVar(comspec . " /c " . var1)
msgbox,%c2%
;fileappend,%c2%,test77.txt
c2=
return

;- https://autohotkey.com/boards/viewtopic.php?f=6&t=791&hilit=stdouttovar
; ----------------------------------------------------------------------------------------------------------------------
; Function .....: StdoutToVar_CreateProcess
; Description ..: Runs a command line program and returns its output.
; Parameters ...: sCmd      - Commandline to execute.
; ..............: sEncoding - Encoding used by the target process. Look at StrGet() for possible values.
; ..............: sDir      - Working directory.
; ..............: nExitCode - Process exit code, receive it as a byref parameter.
; Return .......: Command output as a string on success, empty string on error.
; AHK Version ..: AHK_L x32/64 Unicode/ANSI
; Author .......: Sean (http://goo.gl/o3VCO8), modified by nfl and by Cyruz
; License ......: WTFPL - http://www.wtfpl.net/txt/copying/
; Changelog ....: Feb. 20, 2007 - Sean version.
; ..............: Sep. 21, 2011 - nfl version.
; ..............: Nov. 27, 2013 - Cyruz version (code refactored and exit code).
; ..............: Mar. 09, 2014 - Removed input, doesn't seem reliable. Some code improvements.
; ..............: Mar. 16, 2014 - Added encoding parameter as pointed out by lexikos.
; ..............: Jun. 02, 2014 - Corrected exit code error.
; ..............: Nov. 02, 2016 - Fixed blocking behavior due to ReadFile thanks to PeekNamedPipe.
; ----------------------------------------------------------------------------------------------------------------------
StdoutToVar(sCmd, sEncoding:="CP0", sDir:="", ByRef nExitCode:=0) {
    hstdoutrd:=""
	hstdoutwr:=""
	nTot:=""
	nSize:=""
	sOutput:=""
    DllCall( "CreatePipe",           PtrP,hStdOutRd, PtrP,hStdOutWr, Ptr,0, UInt,0 )
    DllCall( "SetHandleInformation", Ptr,hStdOutWr, UInt,1, UInt,1                 )
	

            VarSetCapacity( pi, (A_PtrSize == 4) ? 16 : 24,  0 )
    siSz := VarSetCapacity( si, (A_PtrSize == 4) ? 68 : 104, 0 )
    NumPut( siSz,      si,  0,                          "UInt" )
    NumPut( 0x100,     si,  (A_PtrSize == 4) ? 44 : 60, "UInt" )
    NumPut( hStdOutWr, si,  (A_PtrSize == 4) ? 60 : 88, "Ptr"  )
    NumPut( hStdOutWr, si,  (A_PtrSize == 4) ? 64 : 96, "Ptr"  )

    If ( !DllCall( "CreateProcess", Ptr,0, Ptr,&sCmd, Ptr,0, Ptr,0, Int,True, UInt,0x08000000
                                  , Ptr,0, Ptr,sDir?&sDir:0, Ptr,&si, Ptr,&pi ) )
        Return ""
      , DllCall( "CloseHandle", Ptr,hStdOutWr )
      , DllCall( "CloseHandle", Ptr,hStdOutRd )

    DllCall( "CloseHandle", Ptr,hStdOutWr ) ; The write pipe must be closed before reading the stdout.
    While ( 1 )
    { ; Before reading, we check if the pipe has been written to, so we avoid freezings.
        If ( !DllCall( "PeekNamedPipe", Ptr,hStdOutRd, Ptr,0, UInt,0, Ptr,0, UIntP,nTot, Ptr,0 ) )
            Break
        If ( !nTot )
        { ; If the pipe buffer is empty, sleep and continue checking.
            Sleep, 100
            Continue
        } ; Pipe buffer is not empty, so we can read it.
        VarSetCapacity(sTemp, nTot+1)
        DllCall( "ReadFile", Ptr,hStdOutRd, Ptr,&sTemp, UInt,nTot, PtrP,nSize, Ptr,0 )
        sOutput .= StrGet(&sTemp, nSize, sEncoding)
    }
    
    ; * SKAN has managed the exit code through SetLastError.
    DllCall( "GetExitCodeProcess", Ptr,NumGet(pi,0), UIntP,nExitCode )
    DllCall( "CloseHandle",        Ptr,NumGet(pi,0)                  )
    DllCall( "CloseHandle",        Ptr,NumGet(pi,A_PtrSize)          )
    DllCall( "CloseHandle",        Ptr,hStdOutRd                     )
    Return sOutput
}
;============================================================
botman
Posts: 4
Joined: 02 Jun 2020, 02:41

Re: get cmd output without file

02 Jun 2020, 03:06

hi! I am a beginner


so, is it work?

what is the type of var? binary?
botman
Posts: 4
Joined: 02 Jun 2020, 02:41

Re: get cmd output without file

02 Jun 2020, 03:11

I'm trying to get hbitmap without output file but need some help :cry:

Code: Select all

ffmpeg -hide_banner -loglevel panic -ss 00:01:00 -i input -frames:v 1 -vf scale=w=320:h=240:force_original_aspect_ratio=decrease -c:v mjpeg -f image2pipe
toralf
Posts: 792
Joined: 27 Apr 2014, 21:08
Location: Germany

Re: get cmd output without file

02 Jun 2020, 05:04

Only the txt that is displayed by ffmpeg in the console is being captured into a variable. I do not believe that ffmpeg prints the binary data to the console.
ciao
toralf
User avatar
hasantr
Posts: 592
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: get cmd output without file

02 Jun 2020, 05:38

Hello, I had a similar problem. I don't want to create a separate crowd of titles.
This command works with cmd but not with ahk functions.

Code: Select all

var1 = dir /S /B /A:-D *.mp3 *.mp4 *.jpg | findstr /V /I /C:"\\Microsoft\\" /C:"\\Windows\\"
toralf
Posts: 792
Joined: 27 Apr 2014, 21:08
Location: Germany

Re: get cmd output without file

02 Jun 2020, 06:38

I assume it does not work with the original AHK function because the command already contains a pipe. But that is just a pure guess.
Thus, you either remove the part after the pipe an do it in AHK or you try to alter the AHK function.
ciao
toralf
botman
Posts: 4
Joined: 02 Jun 2020, 02:41

Re: get cmd output without file

02 Jun 2020, 07:01

Thanks for reply, toralf you're right.


I think "namedpipe" is the solution... :think:
https://autohotkey.com/board/topic/95147-passing-multiline-commandsmessages-through-namedpipe-script/

Code: Select all

ffmpeg -hide_banner -loglevel panic -ss 00:01:00 -i input -frames:v 1 -vf scale=w=320:h=240:force_original_aspect_ratio=decrease -c:v mjpeg -f image2pipe - PipeExample

Return to “Ask For Help”

Who is online

Users browsing this forum: songdg, Xtra and 52 guests