在Powershell中编译Micro Focus Net Express 5.1 Cobol

在Powershell中编译Micro Focus Net Express 5.1 Cobol,powershell,cobol,Powershell,Cobol,我希望有人能帮助我在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 T

我希望有人能帮助我在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调用外部exe/cmd需要特别注意。这是一件有据可查的事情

从Microsoft和其他网站查看这些详细信息:——

  • 接线员&
  • 当外部命令有很多参数时,事情可能会变得棘手 或者参数或路径中有空格

    对于空格,必须嵌套引号,结果不是这样 永远清楚

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

  • cmd/c-使用旧的cmd shell **此方法不应再用于V3
  • 原因:绕过PowerShell并从cmd shell运行命令。经常 与DIR一起使用的时间,该DIR在cmd shell中的运行速度比在 PowerShell(注意:这是PowerShell v2及其 .NET2.0,这不是V3)的问题

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

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

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

    CMD.EXE/C“ICACLS.EXE C:测试/授予用户:(F)”
    

    …还有更多类似的功能。

    通过PowerShell调用外部exe/cmd需要特别注意。这是一件有据可查的事情。查看Microsoft和其他公司提供的这些详细信息:---还有更多类似的信息。谢谢!CMD/C满足了我的需要。不用担心,我会将此评论移至答案部分,以便您可以将其标记为您接受的答案,以方便其他可能遇到此问题的人。
    # 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
    
    # 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
    
    CMD.EXE /C "ICACLS.EXE C:TEST /GRANT USERS:(F)"
    
    <#
    # Results
    
    processed file: C:TEST
    Successfully processed 1 files; Failed processing 0 files
    #>