4
votes

This may be a general question, but I'm new to octave and want to get a string from the command line. However, I'm not sure what format the command line arguments are in. I have attempted typing:

myscript hi
myscript --hi
myscript -hi
myscript (hi)

at the command line but I keep on getting this error:

error: invalid use of script "myscript filepath" in index expression

so I'm apparently not calling this correctly. The --hi is the format that is shown on the official website but it doesn't appear to work for me. This script, I got off online just to test:

#! /usr/bin/octave -qf

printf("%s", program_name());
arg_list = argv();
for i = 1:nargin
    printf(" %s", arg_list{i});
end
printf("\n");

Is there something I need to implement in order for argv to work?

1
Can you post a minimal version of your code that shows the problem? The example code you posted works fine for me, but I'm guessing that's not where your trouble lies. - andyras
It's actually when I run the code on the command line when I have problems. So I type something like: ">myscript --hi" . And what appears is this message: error: invalid use of script C:\Users\Roostersign\Desktop\myscript.m in index expression. I don't understand how to make this stop happening. - roostersign
I guess what I'm asking is: could someone show me how they are running this program on the command line to make sure that I'm not doing something stupid that's causing this error? - roostersign
So you are having trouble running the particular example of code you posted? That works fine for me when I run it, but I am using Linux rather than Windows. I don't know much about using the Windows command line. Perhaps try putting the command line arguments in quotes, like myscript.m "--hi" and see if you get the same error. Also try running the script without any arguments to see if you get an error. - andyras
Er, nevermind. So this error was basically due to a confusion between the Windows command line and the Octave prompt, in addition to some not having the files being in the current directory. Woops. Thank you for your help though. :) - roostersign

1 Answers

0
votes

I am starting too.

Says you have an error in path name. You specify nothing explicit for path (ie c:\root\myfiles\filex.txt) so it probably assumes the file is in your current directory.

If you type ls can you see your file? You can either move the file to the current directory or use the cd command to change the current pointer to where the file is.