2017-05-16 160 views
0

我有一個文件夾位於具有文件input.xml,output.xml和licensegenerator.exe的C:\ Folder中。 Licensegenerator.exe將變量放入input.xml中,並使用output.xml文件爲我們的某個程序創建一個臨時許可證。我們通常通過命令行執行此導航到C:\文件夾目錄,然後運行命令:如何從PowerShell運行* .exe文件

LicenseGenerator.exe "C:\Folder\input.xml" "C:\Folder\output.xml" 

我試圖寫一個腳本做在PowerShell中完全一樣的事情,但我掙扎......這是我有:

$inputtest = "C:\Folder\Input.xml" 
$outputtest = "C:\Folder\Output.xml" 
$licensegen = "C:\Folder\LicenseGenerator.exe" 

Invoke-Command $licensegen "$inputtest" "$outputtest" 

當我運行它,我得到的錯誤:

 
Invoke-Command : A positional parameter cannot be found that accepts argument 
'C:\Folder\Output.xml'. 
At line:5 char:1 
+ Invoke-Command $licengegen "$inputtest" "$outputtest" 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : InvalidArgument: (:) [Invoke-Command], ParameterBindingException 
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeCommandCommand 

我也試圖與Invoke-Expression運行,但得到完全相同的錯誤(除非它說「 Invoke-Expression「開頭)。任何人都知道我在這裏做錯了什麼?

+0

&$ licensegen 「$ inputtest」 取代調用命令 「$ outputtest」 的伎倆。謝謝你們! –

回答

2

您正在尋找的call operator

& $licensegen "$inputtest" "$outputtest" 

Invoke-Command本質上是對其他主機和/或其他用戶上下文中運行scriptblocks。

1

Start-Process 是偉大的,因爲你可以跑動,重定向輸出,隱藏子進程窗口等等。

Start-Process -FilePath $licensegen -Argumentlist $inputtest,$outputtest

-1

& 「[路徑]命令」[參數]

只是&