繁体   English   中英

在Powershell中将参数传递给mysql.exe

[英]Passing arguments to mysql.exe in powershell

我的任务是将批处理脚本转换为Powershell。 该批处理脚本仅将参数传递给mysql.exe即可运行查询并将其导出到.txt文件中。 作为批处理文件运行时,此方法有效,但是由于将其粘贴到powershell中,因此出现以下错误。

码:

cd "C:\PS\mysql" .\mysql.exe --defaults-file=C:\PS\mysql\my.ini
--defaults-group-suffix=marketing -A -n < C:\PS\mysql\SQLGFHW.sql > C:\PS\output.txt

这是我得到的错误:

At C:\PS\googleCons.ps1:3 char:88
+ ... =C:\PS\mysql\my.ini --defaults-group-suffix=marketing -A -n < C:\PS\m ...
+                                                                 ~
The '<' operator is reserved for future use.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : RedirectionNotSupported

我希望<运算符会成为全局对象,并且可以在两个脚本中使用。 PS中有其他方法可以解决此问题吗?

任何帮助表示赞赏。 谢谢

您不能在本地重定向输入。 一种替代方法是使用Start-Process

$spParams = @{
    FilePath               = 'mysql.exe'
    ArgumentList           = @(
        '--defaults-file=my.ini'
        '--defaults-group-suffix=marketing'
        '-A', '-n'
    )
    WorkingDirectory       = 'C:\PS\mysql'
    RedirectStandardInput  = 'SQLGFHW.sql'
    RedirectStandardOutput = 'C:\PS\output.txt'
    Wait                   = $true
}
Start-Process @spParams

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM