通过 Powershell 执行 Accoreconsole.exe 时出现问题

问题描述

我正在尝试运行一个 .ps1,它允许用户从 Windows 对话框中选择文件,然后选择他们希望在每个文件上运行的脚本。然后对于这些文件中的每一个,打开 AutoCAD Core Console 并进行处理。

当我使用 .bat 或直接通过 CMD 运行文件和脚本时,我没有任何问题。当我尝试运行下面的 Powershell 脚本时,我让 Accoreconsole.exe 启动,但它立即关闭。同样的脚本在以前的机器上运行,所以我想知道它是否与安全或执行策略有关?

AcCoreConsole 需要以下格式的输入。我的 powershell 脚本所做的就是尝试重新创建与此类似的路径。

AcCoreConsole.exe [/i] /s [/product] [/l] [/isolate] [/readonly] [/p[rofile] ]

Set-ExecutionPolicy -ExecutionPolicy Unrestricted
#Sets username for initial path and script path
$env:UserName

#Initial path to project Sheets directory
$initialDirectory = "C:\Users\$env:UserName\Desktop\PW Exports\test\"

#Initial path to project Script directory 
$scriptDirectory = "C:\Users\$env:UserName\Desktop\PW Exports\test\" 

#Number of instances of the AutoCAD Core Console at one time - Recommended 5
$Accoreinstance = 1

#This sets the variable for CAD files in an array or list as string values
[array]$CADF = @()
$CADF = Get-CADFiles

#This sets the variable for your script file in an array or list as string values
[array]$SCR = @()
$SCR = Get-Script

#This to bring up Windows dialog prompt to select CAD files to be processed
Function Get-CADFiles($CADF)
{
    [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null

    $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
    $OpenFileDialog.InitialDirectory = $initialDirectory
    $OpenFileDialog.Multiselect = $true
    $OpenFileDialog.Title = "Choose CAD Files The You Wish To Process"
    $OpenFileDialog.ShowDialog() | Out-Null
    $OpenFileDialog.FileNames
}

#This to allow for a second Windows dialog promt to select the script to be run on the files above
Function Get-Script($SCR)
{
    $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
    $OpenFileDialog.InitialDirectory = $scriptDirectory
    $OpenFileDialog.Title = "Choose Script File To Run"
    $OpenFileDialog.ShowDialog() | Out-Null
    $OpenFileDialog.FileName
}

$CADF_list = get-item $CADF
#This takes the selected files from windows dialog and processes
foreach ($file in $CADF_list) {

    #This is to count the number of current AcCore running
    $running = @(Get-Job | Where-Object {$_.State -eq 'Running'})

    #This will wait until the number of instances is lower than what was set on with $Accoreinstance
    if ($running.Count -ge $Accoreinstance) {
        $running | Wait-Job -Any | Out-Null
    }

    Write-Host "Starting to process $file"

    #This will start the running of script on the files
    Start-Job -ScriptBlock {

    #This is where you set which version of Accore you are going to be using to run
    $AccoreVrs = "C:\Program Files\Autodesk\AutoCAD 2020\accoreconsole.exe"
    $arg1 = ' /i ' + $using:file + ' /s ' + $using:SCR 

    # Start the core-console for each instance and set the job to wait until it finishes
    start-process $AccoreVrs $arg1 -wait

    } | Out-Null

}

# Wait for all jobs to complete and results ready to be received
get-job | Wait-Job | Out-Null

# Process the results
foreach($Accoreinstance in Get-Job)
{
    $result = Receive-Job $Accoreinstance
    Write-Host $result
}

Remove-Job -State Completed

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...