命令中的Powershell变量不起作用

时间:2013-12-11 18:20:13

标签: powershell mysqldump

我尝试了很多不同的变体,但我无法让它发挥作用。我正在尝试运行mysqldump来导出数据库(在本例中称为全局)。

PS C:\Users\Administrator> &"$mysqlpath\mysqldump.exe -u$mysqluser -p$mysqlpass --databases global | Out-File $env:TEMP\database_backup\global_$timestamp.sql -Encoding UTF8"
& : The term 'C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqldump.exe -ubackup -pbackup_password --databases global | Out-File C:\Users\ADMINI~1\AppData\Local\Temp\2\database_backup\global_2013-12-11T11:47:28.sql -Encoding UTF8' is
not recognized as the name of a cmdlet, function, script file, or operable program.     Check the spelling of the name, or
if a path was included, verify that the path is correct and try again.
At line:1 char:2
+ &"$mysqlpath\mysqldump.exe -u$mysqluser -p$mysqlpass --databases global | Out-Fi ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Program File... -Encoding UTF8:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

看起来它正在被分解为正确的变量名称,但我无法让它运行。

更新:所以这是正确的答案,我在时间戳中有一个:通过将变量放在双引号(“)

中来解决我的另一个问题

1 个答案:

答案 0 :(得分:2)

您告诉Powershell运行名为

的EXE

&"$mysqlpath\mysqldump.exe -u$mysqluser -p$mysqlpass --databases global | Out-File $env:TEMP\database_backup\global_$timestamp.sql -Encoding UTF8"

删除引号(")然后重试。像这样,

& $mysqlpath\mysqldump.exe -u$mysqluser -p$mysqlpass --databases global | Out-File $env:TEMP\database_backup\global_$timestamp.sql -Encoding UTF8