簡體   English   中英

Powershell無法傳遞命令行字符串參數

[英]Powershell cannot pass in command line string parameter

\\我已經嘗試了我可以在網上找到的所有內容,但我無法完成這項工作....真的很令人沮喪。 我想要做的就是將命令行中的文件名傳遞給我的Powershell腳本test.ps1。

param([String]$input=$args[0])
$inputpath = 'C:\work\'
$inputfile = $($inputpath + $input+".txt")

我運行腳本如:

powershell。\\ test.ps1“輸入”

但是,在我打印出來的錯誤信息中,我不斷收到“找不到c:\\ work \\ .txt”。 顯然我的命令行參數不正確。 有人可以幫忙嗎?

嘗試將$Input更改$Input其他名稱。 因為$Input用於Pipeline變量。

參見例如:

http://blogs.technet.com/b/heyscriptingguy/archive/2010/12/31/write-powershell-functions-that-accept-pipelined-input.aspx

我只是用它來構建路徑:

$inputpath = 'C:\work\'
$inputfile = Join-Path $inputpath ($args[0] + ".txt")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM