简体   繁体   中英

octave-gui invoked by bat script does not work unless you run octave(-gui) before (or “run octave-cli.exe with qt”)

I want to run octave-gui (Octave 5.1 installed with installer and "C:\Octave\mingw64\bin" is in path variable) scripts run by Windows Task Scheduler. I have to run octave-gui since I want to use the qt toolkit for plotting that octave (without gui) does not support. Therefore I normally use simple bat files like "octave-gui --no-gui c:\path\myfile.m".

But the problem is that I cannot run this bat file by clicking in the Windows Explorer or running from command line. Even the most simple bat file with the content "octave-gui --no-gui" gives me the following error:

八度 gui 错误

But the funny part is that I can make it work somehow:

  1. open command line
  2. run "octave" or "octave-gui" and close/quit it
  3. then I can the bat file from the command line

让它运行

But this could not be the solution, could it? This only works in the (interactive) command line. How does it work in the Task Scheduler?

So, do you have a solution to run either batch files using octave-gui or octave with qt toolkit.

Here is the workaround with "where" as asked by Gerhard: 解决方法在哪里

The command octave is technically incorrect.

It works only from your Command Prompt window because its extension .bat is listed within the values assigned to an unmodified environment variable %PATHEXT% . It also assumes that there are no other files named octave.com or octave.exe , anywhere within the any of the directories listed under your environment variable %PATH% . Additionally it also assumes that there is not an executable file named octave with any extension listed under %PATHEXT% in the current directory when invoked.

You should, for safety, use octave.bat instead.

octave.bat

Octave.bat will parse any input arguments, set up the required environment, and then run either start octave-gui.exe --gui %* or octave-cli.exe %* if it detected --no-gui as one of the input arguments.

Additionally when running a batch file from another, (in this case start_my_octave_script.bat ), you should Call it if you're wanting control to return to it afterwards, which will almost certainly be the case.

call octave.bat <command line options>

If you're satisfied that your %PATHEXT% environment variable is unmodified or at least holds the default values, you can omit the .bat extension, but please bear in mind the previous advice.

call octave <command line options>

I made a workaround thanks to the hints made by Compo. It seems to me that a solution must be done in the "octave.bat" and so I did. I made a copy and named it "octave-gui-nogui-withqt.bat" and removed all the gui checking stuff and only run "octave-gui.exe --no-gui" (scroll down):

:; # if running from bash, recall using cmd.exe
:; cmd.exe //c "$0" "$@"; exit $?
@echo off
Rem   Find Octave's install directory through cmd.exe variables.
Rem   This batch file should reside in Octaves installation bin dir!
Rem
Rem   This trick finds the location where the batch file resides.
Rem   Note: the result ends with a backslash.
set OCT_HOME=%~dp0\.\..\
Rem Convert to 8.3 format so we don't have to worry about spaces.
for %%I in ("%OCT_HOME%") do set OCT_HOME=%%~sI

Rem   Set up PATH.  Make sure the octave bin dir comes first.

set PATH=%OCT_HOME%qt5\bin;%OCT_HOME%bin;%PATH%

Rem   Set up any environment vars we may need.

set TERM=cygwin
set GNUTERM=wxt
set GS=gs.exe

Rem QT_PLUGIN_PATH must be set to avoid segfault (bug #53419).
IF EXIST "%OCT_HOME%\qt5\bin\" (
  set QT_PLUGIN_PATH=%OCT_HOME%\qt5\plugins
) ELSE (
  set QT_PLUGIN_PATH=%OCT_HOME%\plugins
)

Rem set home if not already set
if "%HOME%"=="" set HOME=%USERPROFILE%
if "%HOME%"=="" set HOME=%HOMEDRIVE%%HOMEPATH%
Rem set HOME to 8.3 format
for %%I in ("%HOME%") do set HOME=%%~sI

Rem   Start Octave (this detaches and immediately returns).
Rem make this call in order to have qt on the cli
octave-gui.exe --no-gui %*

Is this the most elegant one? I guess that upstream Octave should allow a new option like "--no-gui-but-use-qt" or similar. What do you think? It still confuses me that "octave-cli.exe" and "octave-gui.exe" have more differences besides the visible gui.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM