我正在运行一个脚本,它带有一个文本"rAh%19u ^ l \&G"即包含特殊字符.
当我在我的脚本中将此文本作为参数传递时,它运行正常,没有任何错误.
示例 - : ./abc.py <username><pwd>
以上文字基本上是一个密码.
现在,当我将我的值放在配置文件中并阅读上面的文本时,脚本失败了.
*******abc.ini*******
[DEFAULT]
username = rahul
pwd = rAh%19u^l\&G
Run Code Online (Sandbox Code Playgroud)
它说
/bin/sh:M command not found.
Run Code Online (Sandbox Code Playgroud)
在配置解析器的帮助下阅读上述值
******以下是程序abc.py******
#! /usr/bin/python
parser = configparser.ConfigParser()
parser.read('abc.ini')
username = parser.get('DEFAULT','username')
pwd = parser.get('DEFAULT','pwd')
p = subprocess.Popen(
"abc.py {0} {1}" .format(username, pwd),
shell=True,
stdout=subprocess.PIPE
)
out, err = p.communicate()
print(out)
Run Code Online (Sandbox Code Playgroud)
我试了很多,但没有找到具体的东西.
所以问题是如何读取包含.ini文件中特殊字符的文本.
我想cmd.exe在不同的用户下运行一个常规脚本。
我已经使用过Start-Process,当脚本执行时,它只是用不同的用户在屏幕上打开提示,但不处理$command.
cmd.exe所以我的问题是“使用PowerShell运行后如何传递命令?
这是我到目前为止所拥有的:
$username = "abc"
$pwd = ConvertTo -SecureString "xyz" -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username $pw
$command = "filepath/.groovy"
try {
Start-Process 'cmd' -Credential $cred -ArgumentList $command
Write-Host $LASTEXITCODE
if($LASTEXITCODE -ne 0) {
throw "Error occured"
} else {
return 0
}
} catch {
Write-Error "Error Desc:$_Error.InnerException.Message";
}
Run Code Online (Sandbox Code Playgroud)