在Powershell中编译Micro Focus Net Express 5.1 Cobol

问题描述 投票:0回答:1

我希望有人能够在Powershell中编写COBOL MF Net Express 5.1编译命令。我有原始批处理脚本中使用的命令。我目前正在将Powershell作为构建脚本进行重新处理。

COBOL.EXE "%%inFile%%" OUTDD NOERRQ NOFLAGQ NOQUERY noALTER noanim nobound checkdiv COMP errlist list() FASTLINK omf"gnt" perform-type"osvs" SCHEDULER TARGET"PENTIUM" noTRUNC vsc2(1) listpath"","%%OUTPUT%%";,;,;

我将其转换为Powershell的尝试是这样的:

$cobolExe = ".\COBOL.EXE"
$expression = "& $cobolExe `"$($inputfile)`" OUTDD NOERRQ NOFLAGQ NOQUERY noALTER noanim nobound checkdiv COMP errlist list() FASTLINK omf`"gnt`" perform-type`"osvs`" SCHEDULER TARGET`"PENTIUM`" noTRUNC vsc2(1) listpath`"`", `"$binPath\`";,;,;"
Invoke-Expression $expression

Invoke-Expression: 
Line |
   1 |  Invoke-Expression $expression
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | At line:1 char:97 + … GQ NOQUERY noALTER noanim nobound checkdiv COMP errlist list() FASTLI … +                                                                ~
An expression was expected after '('.  At line:1
     | char:221 + … NTIUM" noTRUNC vsc2(1) listpath"", "C:\dev\dimensions\test\bin\";,;,; +                                                                     ~
Missing expression after unary operator ','.  At line:1
     | char:223 + … NTIUM" noTRUNC vsc2(1) listpath"", "C:\dev\dimensions\test\bin\";,;,; +                                                                       ~
Missing expression after unary operator ','.

我已成功使用CBLLINK.EXE进行此操作,但是它不需要那么多参数。

$cobolFile = "$Path\cobol.dir"
$cbllinkExe = ".\CBLLINK.EXE"

$expression = "$cbllinkExe -s -o$($outputFile) `"$($inputFile)`" adis adisinit adiskey -u`"$cobolFile`""
Invoke-Expression $expression

任何有见识并可以提供帮助的人,我将非常感谢。请让我知道我是否还能提供其他服务?

powershell cobol
1个回答
0
投票

通过PowerShell调用外部exe / cmd需要特别注意。这是有据可查的东西。

请参阅Microsoft和其他公司的这些详细信息:---

PowerShell: Running Executables

  1. 呼叫运营商&
# Example:
& 'C:\Program Files\Windows Media Player\wmplayer.exe' "c:\videos\my home video.avi" /fullscreen

当外部命令具有很多参数时,事情会变得棘手或参数或路径中有空格!

带空格,您必须嵌套引号,而结果却不是永远清楚!

在这种情况下,最好像这样将所有内容分开:

$CMD = 'SuperApp.exe'
$arg1 = 'filename1'
$arg2 = '-someswitch'
$arg3 = 'C:\documents and settings\user\desktop\some other file.txt'
$arg4 = '-yetanotherswitch'

& $CMD $arg1 $arg2 $arg3 $arg4

# or same like that:
$AllArgs = @('filename1', '-someswitch', 'C:\documents and settings\user\desktop\some other file.txt', '-yetanotherswitch')
& 'SuperApp.exe' $AllArgs
  1. cmd / c-使用旧的cmd外壳**此方法不应再与V3一起使用

为什么:绕过PowerShell并从cmd shell运行命令。经常在cmd shell中运行的DIR比在PowerShell(注意:这是PowerShell v2及其对.Net 2.0,这不是V3的问题)。

详细信息:从Powershell中打开CMD提示,然后执行命令并返回该命令的文本。 / c告诉CMD它应该在命令完成后终止。有几乎没有理由将其用于V3。

# Example:
#runs DIR from a cmd shell, DIR in PowerShell is an alias to GCI. This will return the directory listing as a string but returns much faster than a GCI
cmd /c dir c:\windows

Using Windows PowerShell to run old command line tools (and their weirdest parameters)

解决方案2A:使用CMD / C

与第一个问题一样,您可以本身运行CMD.EXE并通过命令及其参数用引号引起来。除了效率,这将起作用很好,因为PowerShell不会尝试解析引号中的字符串。

CMD.EXE /C "ICACLS.EXE C:TEST /GRANT USERS:(F)"

<#
# Results

processed file: C:TEST
Successfully processed 1 files; Failed processing 0 files
#>

..还有更多类似这些。

© www.soinside.com 2019 - 2024. All rights reserved.