【发布时间】:2010-10-18 09:45:04
【问题描述】:
对于我的测试,我使用的是“开始 > 运行”对话框(不是 cmd.exe)。
这很好,我在 log.txt 中得到 9
powershell -Command 4+5 > c:\log.txt
但这不起作用:
powershell -EncodedCommand IAA1ACsANwAgAA== > c:\log.txt
那么在这种情况下我该如何重定向输出呢?
实验代码:
function Test
{
$cmd = { 5+7 }
$encodedCommand = EncodeCommand $cmd
StartProcess "powershell -Command $cmd > c:\log.txt"
StartProcess "powershell -EncodedCommand $encodedCommand > c:\log2.txt"
}
function StartProcess($commandLine)
{
Invoke-WMIMethod -path win32_process -name create -argumentList $commandLine
}
function EncodeCommand($expression)
{
$commandBytes = [System.Text.Encoding]::Unicode.GetBytes($expression)
[Convert]::ToBase64String($commandBytes)
}
【问题讨论】:
标签: powershell output-redirect