如何解决通过 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 举报,一经查实,本站将立刻删除。