微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决通过 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.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?