安排PowerShell命令
我想使用follwing powershell命令自动记录流中VLC的流:
$rd = get-date -format "yyyyMMdd"
C:\"Program Files"\VideoLan\vlc\vlc.exe https://someurl/playlist.m3u --sout "#file{dst=C:\users\me\desktop\$rd.mp3}" --run-time=15 vlc://quit
如果我将其保存为.ps1脚本,然后使用“右键单击>使用PowerShell运行”,则可以很好地奏效。
如果我将这些命令粘贴到PowerShell并将其执行一行,也可以工作:
$rd = get-date -format "yyyyMMdd"; C:\"Program Files"\VideoLan\vlc\vlc.exe https://someurl/playlist.m3u --sout "#file{dst=C:\users\me\desktop\$rd.mp3}" --run-time=15 vlc://quit
如果我从Windows终端中执行此操作,它甚至可以工作:
powershell -command {$rd = get-date -format "yyyyMMdd"; C:\"Program Files"\VideoLan\vlc\vlc.exe https://someurl/playlist.m3u --sout "#file{dst=C:\users\me\desktop\$rd.mp3}" --run-time=15 vlc://quit}
因此,我在Windows任务调度程序中创建了一个任务以自动执行。
这是“操作”选项卡的XML:
<Actions Context="Author">
<Exec>
<Command>powershell</Command>
<Arguments>-noexit -command {$rd = get-date -format "yyyyMMdd"; C:\"Program Files"\VideoLan\vlc\vlc.exe https://someurl/playlist.m3u --sout "#file{dst=C:\users\me\desktop\$rd.mp3}" --run-time=15 vlc://quit}</Arguments>
</Exec>
</Actions>
现在,一旦触发了任务,打开的PowerShell显示了此错误:
The string is missing the terminator: ".
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
我缺少什么?
I want to use the follwing powershell commands to automatically record a stream with vlc:
$rd = get-date -format "yyyyMMdd"
C:\"Program Files"\VideoLan\vlc\vlc.exe https://someurl/playlist.m3u --sout "#file{dst=C:\users\me\desktop\$rd.mp3}" --run-time=15 vlc://quit
That does work well if I save it as a .ps1 script and execute it with "Right Click > Run with PowerShell".
It also works if I paste those commands to the powershell and execute them in one line, like this:
$rd = get-date -format "yyyyMMdd"; C:\"Program Files"\VideoLan\vlc\vlc.exe https://someurl/playlist.m3u --sout "#file{dst=C:\users\me\desktop\$rd.mp3}" --run-time=15 vlc://quit
It even works if I execute this from within the Windows Terminal:
powershell -command {$rd = get-date -format "yyyyMMdd"; C:\"Program Files"\VideoLan\vlc\vlc.exe https://someurl/playlist.m3u --sout "#file{dst=C:\users\me\desktop\$rd.mp3}" --run-time=15 vlc://quit}
So I created a task in the Windows Task Scheduler to automate the execution.
This is the XML of the "Actions" tab:
<Actions Context="Author">
<Exec>
<Command>powershell</Command>
<Arguments>-noexit -command {$rd = get-date -format "yyyyMMdd"; C:\"Program Files"\VideoLan\vlc\vlc.exe https://someurl/playlist.m3u --sout "#file{dst=C:\users\me\desktop\$rd.mp3}" --run-time=15 vlc://quit}</Arguments>
</Exec>
</Actions>
Now, once the task is triggered, the opened PowerShell shows this error:
The string is missing the terminator: ".
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论