简体   繁体   中英

PowerShell: use command output + string as filename

I have a windows program which can download streams, I specify the output. Would like to use as output filename the epoch time + extension (for example mp4). I've tried this example but doesn't work:

PS C:\>streamlink --hls-live-restart -o (Get-Date -Date ((Get-Date).DateTime) -UFormat %s)+".mp4" URL best

How can I format the filename properly?

Solved by myself. The filename has to be output from $() and perform all concatenation operations inside:

PS C:\> echo (Get-Date -Date ((Get-Date).DateTime) -UFormat %s)+".mp4"
1585338575
+.mp4
PS C:\> echo $((Get-Date -Date ((Get-Date).DateTime) -UFormat %s)+".mp4")
1585338562.mp4

Proper command:

streamlink --hls-live-restart -o $((Get-Date -Date ((Get-Date).DateTime) -UFormat %s)+".mp4") URL best

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM