1

Using Windows 10, Octave 4.4.1, and Excel 2016, I have an Octave script (call it "MyOctaveProgram.m") that takes data from a text file ("MyTextFile.txt"), which can be loaded with the uigetfile function, but for quicker access, I've created a batch file:

@echo off
C:\Octave\Octave-4.4.1\octave.vbs --force-gui --eval MyOctaveProgram("'%~d0%~p0'","'%~n0'")
cmd /c

The .bat file has the same name as the .txt file, other than the extension.

So far, this all works fine, and I can execute part of MyOctaveProgram.m via the GUI command line, or through the batch file. The difference comes in when I try to use a part of my code that creates a data table in Excel (with the COM interface), using

xls=xlsopen(ExcelFile)
xls=oct2xls(data...)
xls=oct2xls(more data...)
xls=oct2xls(etc...)
xlsclose(xls)

This works fine when I run MyOctaveProgram.m from the GUI command line (choosing MyTextFile.txt with the uigetfile function), but when I try to create the Excel file when running Octave through the batch script above, I get the following message:

(File pointer preserved. Try saving again later...)

This seems to produce no errors, and the session stays open (unlike the GUI, the batch-initiated Octave session will terminate if there's an error), but the Excel file is not created. There are no other Excel windows or tasks open, and I'm not trying to overwrite an existing file. Any advice would be appreciated!

5
  • 1
    The error you get seems to relate to this: github.com/Microsoft/vscode/issues/101 . Which indicates that perhaps the xlsclose command is not completed when in batch mode; perhaps this is an asynchronous call which takes time? In this scenario, perhaps being in the gui allows time for the process to finish, whereas in batch mode, if the batch process finishes before the asynchronous xlsclose call does, then you get an unsaved file situation. Does adding a pause for a few seconds resolve the problem in batch mode? Commented Apr 23, 2021 at 8:42
  • What happens on using a batch file containing just the command line @%SystemRoot%\System32\cscript.exe //NoLogo "C:\Octave\Octave-4.4.1\octave.vbs" --force-gui --eval MyOctaveProgram("'%~dp0'"^,"'%~n0'") and nothing else and run this batch file from within a command prompt window by typing its full qualified file name (drive + path + name + extension) enclosed in " and pressing ENTER or RETURN instead of double clicking on this batch file? Commented Apr 23, 2021 at 15:19
  • Tasos, the pausing didn't seem to change it. I put "pause(5)" before & after "xlsclose(xls)". If it should be placed elsewhere, please LMK. Mofi, same thing with that batch file. I narrowed it down. Creating the variable "filename" for xlsopen(filename,1), I'm using the input function, i.e. description = input('Input file description: ',"s"); filename = ["Output-" description ".xlsx"]; xls = xlsopen(filename,1); This doesn't work (same as original problem), but filename="Output.xlsx"; works. This isn't a permanent solution; I need multiple files, but getting there! Commented Apr 23, 2021 at 18:59
  • are you able to check whether this problem persists on a current version of Octave? Commented Apr 23, 2021 at 19:53
  • Nick, not yet, but I'll try that if this doesn't work. I think I pinpointed the problem, so I'm able to ask a more specific question. I thought it would be better to post a new question instead of making this one more convoluted, I hope that's appropriate. stackoverflow.com/questions/67245152/… Commented Apr 24, 2021 at 16:43

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.