2014-03-05 23 views
0

我下面從Windows機器上重置MySQL服務器的密碼MySQL網站的instructions ..如何讓周圍的「 - 」操作僅適用於變量或屬性

逐字複製命令:

C:\> "C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqld-nt.exe" 
    --defaults-file="C:\\Program Files\\MySQL\\MySQL Server 5.0\\my.ini" 
    --init-file=C:\\mysql-init.txt 

給了我這個錯誤(略):

Unexpected token 'defaults-file="C:\Program Files\MySql\Mysql Server 5.0\my.ini"' 
in expression or statement. 

The '--' operator works only on variables or on properties. 

+ CategoryInfo   :ParserError: (:) [], ParentContainsErrorRecordException 
+ FullyQualifiedErrorId :UnexpectedToken 

我環顧四周,發現this建議:

Try this:

$cmd= {cmd /c 'C:\Program Files\PostgreSQL\8.3\bin\pg_dump.exe "--encoding=UTF8 --verbose --create --username=postgres -- file=C:\db\Wednesday.pg DB"'}

&$cmd

-- is the Powershell decrement operator. To make it "mundate", it needs to be enclosed in single quotes to suppress parsing it as an operator. You could also escape all the hyphens with backticks, but that's going to get really ugly.

我嘗試下面這種格式..即

$cmd = {cmd /c 'C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqld-nt.exe 
    "--defaults-file="C:\\Program Files\\MySQL\\MySQL Server 5.0\\my.ini 
    --init-file=C:\\mysql-init.txt"'} 
&$cmd 

但後來我得到這個錯誤:

'C:\Program' is not recognised as an internal or external command 

我也試着做反勾逃逸:

C:\> "C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqld-nt.exe" 
    `-`-defaults-file="C:\\Program Files\\MySQL\\MySQL Server 5.0\\my.ini" 
    `-`-init-file=C:\\mysql-init.txt 

但也有錯誤(簡稱):

unexpected token '`-`-defaults-file.. ' in expression or statement 

有什麼想法嗎?

回答

0

我覺得你的命令應該是:

$cmd = {cmd /c '"C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqld-nt.exe" 
--defaults-file="C:\\Program Files\\MySQL\\MySQL Server 5.0\\my.ini" 
--init-file="C:\\mysql-init.txt"'} 

你缺少雙引號

+0

沒了..同樣的錯誤仍然 – abbood

+0

當您在運行會發生什麼命令行? – user3

+0

同樣的錯誤:'C:\程序不被識別爲內部或外部命令,可操作程序或批處理文件' – abbood

1

嘗試PowerShell的V3轉義序列--%

PS > echoargs --% --defaults-file="C:\\Program Files\\MySQL\\MySQL Server 5.0\\my.ini" 

Arg 0 is <--defaults-file=C:\\Program Files\\MySQL\\MySQL Server 5.0\\my.ini> 

Command line: 
"C:\Windows\EchoArgs.exe" --defaults-file="C:\\Program Files\\MySQL\\MySQL Server 5.0\\my.ini" 
0

停止參數處理的雙破折號對於Powershell來說確實是一個不幸的選擇。 我試圖得到它通過調用命令的工作,但下面的示例中效果最好

&"C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqld-nt.exe" '--defaults-file=""C:\Program Files\MySQL\MySQL Server 5.0\my.ini""' '--init-file="C:\mysql-init.txt"' 

雙引號之間的可執行文件。

而且單引號之間的每一個參數,用雙引號之間的參數值(或雙擊雙引號,以使路徑的工作空間)

相關問題