【问题标题】:Passing arguments to mysql.exe in powershell在powershell中将参数传递给mysql.exe
【发布时间】:2019-12-13 00:08:56
【问题描述】:

我的任务是将批处理脚本转换为 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

我预计

感谢任何帮助。 谢谢

【问题讨论】:

    标签: mysql powershell parameters arguments


    【解决方案1】:

    您不能在 中本地重定向输入。一种替代方法是使用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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-08-01
      • 2019-02-09
      • 2022-01-05
      • 1970-01-01
      • 1970-01-01
      • 2023-03-26
      相关资源
      最近更新 更多