PowerShell在命令字符串中使用连接符调用表达式 [英] PowerShell Invoke-Expression with Ampersand in the Command String

查看:1055
本文介绍了PowerShell在命令字符串中使用连接符调用表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图传递一个变量,其中包含一个和号到invoke-expression的字符串,它告诉我,我必须把它放在引号中,并将其作为字符串传递。我试过多个组合的转义和使用原始字符串和变量中的字符串与和的组合无效。谁能帮助我在这里?这里是代码:

I am trying to pass a variable with a string that contains an ampersand into invoke-expression and it is telling me I have to put it in quotations and pass it as a string. I've tried multiple combinations of escaping and using a raw string and a string in a variable with combinations of "" and '' to no avail. Can anyone help me out here? Here's the code:

$streamout_calmedia01 = `
"rtmp://75.126.42.216/livepkgr/calmedialive01?adbe-live-event=liveevent&adbe-record-mode=record"


$streamcmd_calmedia01 = "C:\avconv\usr\bin\avconv.exe 'rtmp://75.126.42.211/transcoder/mobileingest live=1' -f flv -c:v libx264 -r 30 -g 120 -b:v 410000 -c:a aac -ar 22050 -b:a 64000 -strict experimental -y $streamout_calmedia01"

Invoke-Expression "$streamcmd_calmedia01"

尝试在符号之前使用`,并在引入变量之前在invoke表达式前使用双引号,我试过(如图所示)使用-Co​​mmand for Invoke-Expression以及将&和&并将&符串连接到字符串。任何想法将是非常感谢!我需要在其中的Ampersand,以便Flash Media Server在开始HTTP Live Streaming分块之前从流名称解析命令并刷新先前记录的数据。

I've tried using a ` before the Ampersand and using a double quotation in front of invoke expression before putting in the variable, I've tried (as is shown) putting quotations around the variable with the -Command for the Invoke-Expression and also putting '&' and "&" and concatenating the ampersand to the string. Any ideas would be GREATLY appreciated! I need the Ampersand in there for Flash Media Server to parse the command out of the stream name and flush prior recorded data before beginning HTTP Live Streaming chunking.

推荐答案

&符号必须在里面双引号。 ;,因此您需要转义内部双引号

The ampersand must be double-quoted inside the string "&", so you need to escape the inner double quotes

$streamout_calmedia01 = "rtmp://...vent`"&`"adbe-record-mode=record"

或put

$streamout_calmedia01 = 'rtmp://...vent"&"adbe-record-mode=record'

这篇关于PowerShell在命令字符串中使用连接符调用表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆