八度输入功能,通过批处理文件运行 [英] Octave 'input' function, run through batch file

查看:66
本文介绍了八度输入功能,通过批处理文件运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用批处理文件:

I am using a batch file:

@echo off
C:\Octave\Octave-4.4.1\octave.vbs --force-gui --eval batchTest("'%~dp0'")
cmd /c

运行八度脚本

function [] = batchTest(fPath)

disp(fPath);
cd(fPath);

optionNumber = input('Choose option 1 or 2:  ');

if optionNumber == 1            
    fName = input('Input file description:  ',"s");
    filename = [fName ".xlsx"];
    xls = xlsopen(filename,1);       % <-- THIS DOES NOT WORK, PRODUCES "FILE POINTER PRESERVED MESSAGE"
    xls = oct2xls({"OutputData"},xls,1,"A1");
    xlsclose(xls);
end

if optionNumber == 2            
    filename = "TestFile.xlsx";
    xls = xlsopen(filename,1);           %  <-- THIS WORKS AS EXPECTED
    xls = oct2xls({"OutputData"},xls,1,"A1");
    xlsclose(xls);
end

在批处理文件的目录中创建Excel文件.

to create an Excel file in the batch file's directory.

选项号1产生一个保留文件指针".警告,并且未创建Excel文件.看来我无法使用由Octave的输入"功能创建的全部或部分字符串.用".xlsx"输入完整文件名.并将该变量传递给'xlsopen'函数无济于事.选项2运作良好,但是我需要产生多个文件,因此"fName"描述符很重要.我尝试将SETLOCAL ENABLEDELAYEDEXPANSION添加到批处理文件中.我还尝试了一种解决方法,在其中使用了选项2,然后添加了

Option number 1 produces a "File pointer preserved" warning, and the Excel file is not created. It seems that I can't use any string that was created, in whole or in part, by Octave's 'input' function. Inputting the full filename with ".xlsx" and passing that variable to the 'xlsopen' function does not help. Option 2 works fine, but I need to produce multiple files, so the "fName" descriptor is important. I've tried adding SETLOCAL ENABLEDELAYEDEXPANSION to the batch file. I've also tried a work-around where I used Option 2, and then added

rename("TestFile.xlsx",[fName ".xlsx"])

八度脚本,但这会产生一个无效输入".重命名"函数中的错误,因此它也不喜欢输入"创建的字符串.问题仅在于"xlsopen"和重命名"功能.输入"功能可以很好地选择选项编号.

to the Octave script, but this produces an "invalid input" error in the 'rename' function, so it doesn't like the 'input'-created string either. The problem is only with the 'xlsopen' and 'rename' functions; the 'input' function works just fine for choosing the option number.

从Octave命令行直接执行"batchTest(pwd)"时,这两个选项均有效.该问题仅在从批处理文件执行时出现.任何建议将不胜感激.

Either option works when directly executing 'batchTest(pwd)' from the Octave command line. The issue only arises when executing from the batch file. Any advice would be much appreciated.

推荐答案

问题听起来是,当您创建字符串时,您包括的转义字符会弄乱您的文件名.

The issue sounds to be that when you create your string, you are including escaped characters that mess up your filename.

在评论的讨论中,似乎在字符串中包含了回车符,导致文件名错误.

From the discussion in the comments it seems the carriage return character is being included in your string, resulting in a wrong filename.

目前尚不清楚为什么只有从批处理文件运行时才如此,但作为解决方法,您可以通过使用 strtrim 预处理字符串输入以删除所有回车符来确保删除回车符不需要的空格.

It is unclear why this is only the case when running from the batch file, but as a workaround, you can ensure that the carriage return is removed by preprocessing your string input with strtrim to remove any unwanted whitespace.

这篇关于八度输入功能,通过批处理文件运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆