【发布时间】:2017-11-30 03:28:25
【问题描述】:
下面是我的 power shell 脚本中调用批处理文件(带参数)的行,我得到一个位置参数错误。
有人可以帮助您了解如何使用 powershell 脚本中的参数调用批处理文件以及如何从批处理文件中捕获该输入参数。谢谢
我的 Power shell 脚本中的行:
启动进程 "cmd.exe" "/c D:\load.bat" "$Password"
--Error:
**PS D:\Oracle\Scripts\Obi> .\XYZ.ps1
Start-Process : **A positional parameter cannot be found that accepts argument 'password'.**
At D:\.ps1:4 char:1
+ Start-Process "cmd.exe" "/c D:\load.bat" "$Password"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Start-Process], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.StartProcessCommand**
批处理文件 (load.bat) 中的脚本:
set "Var=%1"
for %%i in (*.csv) do (
sqlldr USERID=userid/%Var%@server:prot/domain, CONTROL=control.ctl, LOG=logfile.log,ERRORS=9999 data='%%i' direct='true'
move %%i D:\backup
)
【问题讨论】:
-
为什么需要批处理文件?只需直接从 PowerShell 运行您想要的命令。
-
我需要批处理,因为它会触发一系列 sql 过程和函数。将所有内容转换为PS将是一项艰巨的任务。有没有办法从我的 PS 调用批处理?
-
您可以将批处理文件作为可执行文件运行
-
下面也用过
-
Start-Process "D:\load.bat" $PasswordStart -Process:ID 为 391020 的进程未运行。在 D:\Oracle\Scripts\Obi\OBIEE_Load_Process.ps1:4 char:1 + Start-Process "D:\load.bat" $Password + ~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [开始-进程],ArgumentException + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.StartProcessCommand
标签: powershell batch-file