简体   繁体   English

在 Windows 中使用 Octave 来“编辑”记事本文件而不是“打开”

[英]Using Octave to "Edit" notepad file instead of "Open" in Windows

I use Windows 10 and an.exe program (in-house code written by a colleague) that imports data from.txt files.我使用 Windows 10 和从 .txt 文件导入数据的 an.exe 程序(同事编写的内部代码)。 Since 99% of my use of.txt files are for this program, I've changed the default Windows program so that this.exe file is run automatically when opening a.txt file.由于 99% 的我使用的 .txt 文件都用于该程序,因此我更改了默认的 Windows 程序,以便在打开 .txt 文件时自动运行 this.exe 文件。 If I need to access the.txt file directly, or use it for another purpose, I right-click and choose "edit."如果我需要直接访问 .txt 文件,或者将其用于其他目的,我右键单击并选择“编辑”。

I'm now writing a program of my own (using Octave 4.4.1), which also uses.txt files that sometimes need to be opened/edited, but if I use "open(filename)" in my Octave script, of course it just opens the.exe file.我现在正在编写自己的程序(使用 Octave 4.4.1),它还使用有时需要打开/编辑的 .txt 文件,但如果我在 Octave 脚本中使用“open(filename)”,当然它只是打开 .exe 文件。 I can open the.txt file from there, but I'd like to skip this middle step, since the aforementioned.exe program is not intended to be used in this process, and there are other users of my code that don't have the.exe program installed.我可以从那里打开 .txt 文件,但我想跳过这个中间步骤,因为前面提到的.exe 程序不打算在这个过程中使用,而且我的代码还有其他用户没有.exe 程序安装。

Is there a way to duplicate the right-click/edit feature in Windows within Octave code?有没有办法在 Octave 代码中复制 Windows 中的右键单击/编辑功能? "edit(filename)" opens the file in the native Octave editor, which is technically viable, but not exactly a desirable scenario. “edit(filename)”在本机 Octave 编辑器中打开文件,这在技术上是可行的,但并不完全是理想的场景。 I've also tried changing the default Octave editor to Notepad, and I've tried Notepad++ as well, but I have had absolutely no luck, even with significant effort, of making Octave use an external default editor of any kind (even when I remove the.exe program as the default for.txt files).我还尝试将默认的 Octave 编辑器更改为记事本,并且我也尝试过 Notepad++,但我绝对没有运气,即使付出了巨大的努力,让 Octave 使用任何类型的外部默认编辑器(即使当我删除 .exe 程序作为默认的 for.txt 文件)。 Thanks in advance for any advice you can offer.提前感谢您提供的任何建议。

You can send command-line commands from Octave using thesystem() function.您可以使用system() function 从 Octave 发送命令行命令。

For example, to open the file in notepad, you could do例如,要在记事本中打开文件,您可以这样做

[status, output] = system("notepad <path_to_text_file>.txt");

If notepad isn't in your system path, you will have to add it to or use the full path to the notepad executable如果notepad不在您的系统路径中,则必须将其添加到或使用记事本可执行文件的完整路径

Or, if you want to use Notepad++, add it to your system path and then do或者,如果您想使用 Notepad++,请将其添加到您的系统路径,然后执行

[status, output] = system("notepad++ <path_to_text_file>.txt");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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