English 中文(简体)
电力输出 壳牌
原标题:
  • 时间:2009-05-28 04:22:36
  •  标签:

第一,背景不多。

我的任务是使用全球公益物(gnupg.org)将档案与Powerhell书写。 具体的“Im”呼吁只是gpg.exe。 每当我执行指挥时,我就掌握产出。

例如,我在权力领域进口了以下公用钥匙:

& $gpgLocation --import "key.txt"

美元gpgLocation只是gpg.exe(亏损为“C:Program filesGNUGnuPGgpgpg.exe”)的档案地点。

我在此提出的整个问题是,如果我尝试:

& $gpgLocation --import "key.txt" | out-file gpgout.txt

我获得的所有文件都是一刀切的,名称是适当的,但是COMLETELY空白。 我曾尝试过几条旗帜,以便看一下我是否走进了车库。

我也试图将指挥权送交这部法典(并用通常的档案记录等记录产出):

param
(
    [string] $processname, 
    [string] $arguments
)

$processStartInfo = New-Object System.Diagnostics.ProcessStartInfo;
$processStartInfo.FileName = $processname;
$processStartInfo.WorkingDirectory = (Get-Location).Path;
if($arguments) { $processStartInfo.Arguments = $arguments }
$processStartInfo.UseShellExecute = $false;
$processStartInfo.RedirectStandardOutput = $true;

$process = [System.Diagnostics.Process]::Start($processStartInfo);
$process.WaitForExit();
$process.StandardOutput.ReadToEnd();

任何想法? 我!

最佳回答

您所期望的产出是否达到标准操作或标准退出?

这项工作?

& $gpgLocation --import "key.txt" 2>&1 | out-file gpgout.txt
问题回答

你们也可以使用下文所示的“外部主人”。

& $gpgLocation --import "key.txt" | Out-Host

偷盗的答案是巨大的。 我在答复中补充说,如果出现错误,我就需要采取额外行动。

你们也可以把外壳的产物储存成像这样的变量。 那么,你可以根据上述结果处理错误。

$out = $gpgLocation --import "key.txt" 2>&1
if($out -is [System.Management.Automation.ErrorRecord]) {
    # email or some other action here
    Send-MailMessage -to me@example.com -subject "Error in gpg " -body "Error:`n$out" -from error@example.com -smtpserver smtp.example.com
}
$out | out-file gpgout.txt

而且,权力 壳牌照只能捕获一些方案的产出,因为它们没有书写,不停。 可以通过在PowerShell ISE(在2.0CTP 3版本中)实施该方案来核实。

权力 壳牌ISE能够显示图形色色体中的产出,然后,你可以捕捉这种产出,并且可能需要其他方式使该方案自动化。

在将全球公益物自动化时,你需要使用——批量交换机。 EXE, as in:

& $gpgLocation --import "key.txt" --batch | out-file gpgout.txt

没有这一交换,全球公益物可能会等待用户的投入。





相关问题
热门标签