从PowerShell运行八度脚本并等待完成
我正在尝试从PowerShell运行一个非常简单的八度.m文件,但我无法让PowerShell等待它完成。实际上,它启动了脚本执行,但随后立即开始执行下一行。
正如我说的那样,脚本真的很简单,只是一个测试
a=100
% Saving just to be sure that the script excuted
save test.mat a
% Pausing to be sure that the execution is not too fast
pause(10)
disp("no way")
,在PowerShell中,我只是运行
octave --persist test.m
,但提示不等待八度执行。似乎某种程度上它在另一个过程中会运行异步。
我尝试使用Wait选项从Batch运行脚本
START /W octave --persist test.m
,但结果仍然相同。
谢谢
编辑1
感谢@trey nuckolls我正在使用此补丁:
$Donefilename = 'done'
if (Test-Path $Donefilename) {
Remove-Item $Donefilename
Write-Host "Last execution $Donefilename has been deleted"
}
else {
Write-Host "$Donefilename doesn't exist"
}
octave --persist test.m
do{
$i++
Start-Sleep -Seconds 2
$OctaveComplete = Test-Path -Path $Donefilename
}
until ($OctaveComplete -or ($i -eq 30))
使八度脚本在执行结束时编写一个空的“完成”文件。虽然不是最好的解决方案;例如,我无法重定向执行输出。
编辑2
因此,由于您的所有回答和评论,我设法找到了问题。看来,当我从Windows调用八度
时,它没有调用可执行文件,而是其他的。获取正确的路径和执行:
& "C:/Program Files/GNU Octave/Octave-6.4.0/mingw64/bin/octave-cli.exe" test.m
完美工作(您需要在脚本末尾添加exit
)。因此,这是一条道路问题。
I'm trying to run a very simple octave .m file from Powershell but i can't manage to make powershell wait for it to finish. In fact, it launches the script execution but then immediatly starts executing the next line.
As I said the script is really simple, just a test
a=100
% Saving just to be sure that the script excuted
save test.mat a
% Pausing to be sure that the execution is not too fast
pause(10)
disp("no way")
And in powershell I simply run
octave --persist test.m
but prompt doesn't wait for octave to finish execution. It seems somehow it runs it async in another process.
I've tried running the script from batch with the wait option
START /W octave --persist test.m
but the result still the same.
Thanks in advance
EDIT 1
Thanks to @Trey Nuckolls I'm using this patch:
$Donefilename = 'done'
if (Test-Path $Donefilename) {
Remove-Item $Donefilename
Write-Host "Last execution $Donefilename has been deleted"
}
else {
Write-Host "$Donefilename doesn't exist"
}
octave --persist test.m
do{
$i++
Start-Sleep -Seconds 2
$OctaveComplete = Test-Path -Path $Donefilename
}
until ($OctaveComplete -or ($i -eq 30))
Making the octave script writing an empty "done" file at the end of execution. Not the best solution although; I'm not able to redirect the execution output for example.
EDIT 2
So, i managed to find the problem thanks to all your responses and comments. It seems that when i was calling octave
from windows it wasn't calling the executable but something else. Getting the right path and executing:
& "C:/Program Files/GNU Octave/Octave-6.4.0/mingw64/bin/octave-cli.exe" test.m
works perfectly (you need just to add exit
at the end of the script). So, it was a matter of path.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能会考虑将等待循环放入调用脚本中……
这将在调用八度的行之后直接进行。
You might consider putting a wait loop into your invoking script like...
This would go directly after the line that invokes Octave.