Windows Powershell';s启动进程命令不';如果您在Powershell ise之外,则无法启动exe
我正在编写一个简单的脚本,将一个项目从Teamcenter取消归档(rar)到临时目录,然后运行特定的程序(Mentor),然后再次归档 我读过很多关于从PS启动exe的例子,但它们大多与小的exe有关,比如记事本,没有DLL和其他资源 在Powershell中,脚本可以完美地工作。但当我从teamcenter调用脚本时,Mentor缺少DLL 在我运行Mentor之前,在脚本中,我会:Windows Powershell';s启动进程命令不';如果您在Powershell ise之外,则无法启动exe,windows,powershell,batch-file,environment-variables,Windows,Powershell,Batch File,Environment Variables,我正在编写一个简单的脚本,将一个项目从Teamcenter取消归档(rar)到临时目录,然后运行特定的程序(Mentor),然后再次归档 我读过很多关于从PS启动exe的例子,但它们大多与小的exe有关,比如记事本,没有DLL和其他资源 在Powershell中,脚本可以完美地工作。但当我从teamcenter调用脚本时,Mentor缺少DLL 在我运行Mentor之前,在脚本中,我会: Get-ChildItem Env: 检查环境变量和所有变量是否存在。我尝试手动设置环境,如下所示: $w
Get-ChildItem Env:
检查环境变量和所有变量是否存在。我尝试手动设置环境,如下所示:
$wf_classpath = Get-ChildItem Env:WF_CLASSPATH
[System.Environment]::SetEnvironmentVariable("WF_CLASSPATH", $wf_classpath.Value, "Process")
不起作用
我试图设置homefolder:
$mentor = Start-Process $file.FullName -Wait -WorkingDirectory $workdir
不起作用
然后我尝试从脚本中调用一个批处理文件,但在环境中不起作用
尝试调用cmd.exe/c…
无效
这里的完整脚本,仅在Powershell Ise中工作完美,如果我从其他程序调用脚本,exe不会启动
$shell = new-object -com shell.application
$invocation = $MyInvocation.MyCommand.Definition
$rootpath = $PSScriptRoot
$outpath = "$($PSScriptRoot)\out"
$pathtorar = "c:\Siemens\menutils\Rar.exe"
Remove-Item -Recurse -Force $outpath
New-Item $outpath -ItemType directory
$archive = get-childitem $rootpath | where { $_.extension -eq ".rar" } | Select-Object -First 1
$arglist = "x $($archive.FullName) $($outpath)"
Start-Process -FilePath $pathtorar -ArgumentList $arglist -Wait
Remove-Item -Recurse -Force $archive.FullName
$file = get-childitem $outpath -Recurse | where { $_.extension -eq ".prj" } | Select-Object -First 1
Write-Host "$(get-date -Format yyyy-MM-dd-hh-ss)
Start process: $($file.FullName)"
$mentor = Start-Process $file.FullName -Wait
$arglist = "a -m0 -r -ep1 $($archive.FullName) $($outpath)"
Start-Process -FilePath $pathtorar -ArgumentList $arglist -Wait
Remove-Item -Recurse -Force $outpath
Read-Host -Prompt "Press Enter to exit"
从Powershell Ise和其他程序运行脚本有什么区别
我应该如何设置环境变量以从其他脚本/程序运行脚本?根据我的经验,可能是您当前的目录不正确,
WorkingDirectory
存在缺陷。如果dll不在常规系统路径上,则将从当前目录获取dll
在启动流程之前使用此功能
[IO.Directory]::SetCurrentDirectory($Dir)
谢谢,我明天会试试的。