Guru3D.com Forums

Go Back   Guru3D.com Forums > General > Programming/Html
Programming/Html C++,Visual Basic,HTML,Flash,OpenGL,Modelling,Java.



Reply
 
Thread Tools Display Modes
Pipes in PowerShell
Old
  (#1)
Anarion
Ancient Guru
 
Anarion's Avatar
 
Videocard: EVGA GeForce GTX 1070 ACX
Processor: Intel Core i7 3770K
Mainboard: ASUS P8Z77-V
Memory: G.SKILL RipjawsX 16 GB
Soundcard: Sound Blaster Zx + HD 595
PSU: Corsair AX760
Default Pipes in PowerShell - 09-30-2015, 15:06 | posts: 12,906 | Location: Finland

Any PowerShell gurus around?

I just can't figure out how to pipe command line program output to another command line program... What would be the powershell way to achieve this:
Code:
ffmpeg.exe -i "input.flac" -f wav {more args...} - | lame.exe {args go here} - "output.mp3"
I.e. FFmpeg reads file and send the output directly to Lame through pipeline.

Last edited by Anarion; 09-30-2015 at 15:10.
   
Reply With Quote
 
Old
  (#2)
lmimmfn
Ancient Guru
 
lmimmfn's Avatar
 
Videocard: MSI 980 Ti
Processor: 6800K@4.1Ghz
Mainboard: ASRock x99 Taichi
Memory: 16GB DDR4
Soundcard: Asus Xonar DGX
PSU: OCZ 1250
Default 09-30-2015, 19:04 | posts: 10,233 | Location: Ireland

Is that even possible? I mean in linux the binary output of ffmpeg would have to go to std out which wouldn't normally make sense ( off the top of my head I can't think of any Linux commands that would send binary to std out unless its a user running e.g. cat on a binary file )
   
Reply With Quote
Old
  (#3)
Anarion
Ancient Guru
 
Anarion's Avatar
 
Videocard: EVGA GeForce GTX 1070 ACX
Processor: Intel Core i7 3770K
Mainboard: ASUS P8Z77-V
Memory: G.SKILL RipjawsX 16 GB
Soundcard: Sound Blaster Zx + HD 595
PSU: Corsair AX760
Default 10-01-2015, 10:13 | posts: 12,906 | Location: Finland

Quote:
Originally Posted by lmimmfn View Post
Is that even possible? I mean in linux the binary output of ffmpeg would have to go to std out which wouldn't normally make sense ( off the top of my head I can't think of any Linux commands that would send binary to std out unless its a user running e.g. cat on a binary file )
Oh it totally works in linux and works in windows batch scripts too.
   
Reply With Quote
Old
  (#4)
mbk1969
Ancient Guru
 
mbk1969's Avatar
 
Videocard: GeForce GTX 970
Processor: I7-4930
Mainboard: Asus p9x79
Memory: G Skill RipjawZ, 16GB
Soundcard: Onboard + FiiO E17
PSU: 1000 W
Default 10-02-2015, 13:35 | posts: 3,507 | Location: Moscow, Russia

Quote:
Originally Posted by Anarion View Post
Any PowerShell gurus around?

I just can't figure out how to pipe command line program output to another command line program... What would be the powershell way to achieve this:
Code:
ffmpeg.exe -i "input.flac" -f wav {more args...} - | lame.exe {args go here} - "output.mp3"
I.e. FFmpeg reads file and send the output directly to Lame through pipeline.
Code:
ffmpeg.exe -i "input.flac" -f wav {more args...} - | foreach { lame.exe $_ - "output.mp3" }
Am I correct assuming that ffmpeg.exe outputs one string which one you should pass to the lame.exe ?

Common syntax for cases when first program outputs one single string:
Code:
$var = some1.exe
some2.exe -arg $var

# or

some1.exe | foreach { some2.exe -arg $_ }
In cases when first program outputs more than one string syntax is:
Code:
some1.exe | foreach { some2.exe -arg $_ }
$_ - stands for current value passed through pipeline.

Last edited by mbk1969; 10-02-2015 at 13:58.
   
Reply With Quote
 
Old
  (#5)
Anarion
Ancient Guru
 
Anarion's Avatar
 
Videocard: EVGA GeForce GTX 1070 ACX
Processor: Intel Core i7 3770K
Mainboard: ASUS P8Z77-V
Memory: G.SKILL RipjawsX 16 GB
Soundcard: Sound Blaster Zx + HD 595
PSU: Corsair AX760
Default 10-11-2015, 15:23 | posts: 12,906 | Location: Finland

It doesn't seem to work. I think the PS escapes the data the first program is churning out or something. Oh well... It may not be possible to do this with PS.

Also running command line applications in PS is a small pain in the arse.

This works well but piping data is not possible as far as I know:
Code:
start -FilePath $pathtoapp -Args $appargs -NoNewWindow -Wait
Code:
$app = "S:\something\something.exe"
            
#Works:
&($app) -i something.txt -o something2.txt

#Doesn't work because it thinks that there's one arg ("-i something.txt -o something2.txt")
$args = "-i something.txt -o something2.txt"
&($app) $args
   
Reply With Quote
Old
  (#6)
mbk1969
Ancient Guru
 
mbk1969's Avatar
 
Videocard: GeForce GTX 970
Processor: I7-4930
Mainboard: Asus p9x79
Memory: G Skill RipjawZ, 16GB
Soundcard: Onboard + FiiO E17
PSU: 1000 W
Default 10-11-2015, 20:14 | posts: 3,507 | Location: Moscow, Russia

Describe here what task you are seeking.

I tried the following:
Code:
$qq = C:\Tools\SysinternalsSuite\autorunsc.exe
$qq
Code:
$qq = C:\Tools\SysinternalsSuite\autorunsc.exe -b
$qq
Code:
$qq = &("C:\Tools\SysinternalsSuite\autorunsc.exe") -b
$qq
Code:
$aa = "-b"
$qq = &("C:\Tools\SysinternalsSuite\autorunsc.exe") $aa
$qq

And PS prints me all strings that program did output and which PS did save into variable.

You can`t use name "args" for variable because it has predefined meaning: $args - input arguments for a script, function, script block.
Quote:
$Args
Contains an array of the undeclared parameters and/or parameter values that are passed to a function, script, or script block.
When you create a function, you can declare the parameters by using the param keyword or by adding a comma-separated list of parameters in parentheses after the function name.

In an event action, the $Args variable contains objects that represent the event arguments of the event that is being processed. This variable is populated only within the Action block of an event registration command. The value of this variable can also be found in the SourceArgs property of the PSEventArgs object (System.Management.Automation.PSEventArgs) that Get-Event returns.
When you assign any value to $args PS doesn`t show error - it just silently ignores the assignment.

Last edited by mbk1969; 10-11-2015 at 20:28.
   
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles.com
Copyright (c) 2017, All Rights Reserved. The Guru of 3D, the Hardware Guru, and 3D Guru are trademarks owned by Hilbert Hagedoorn.