bugGNU Octave - Bugs: bug #49383, Command-line options counted as as...

 
 

bug #49383: Command-line options counted as as input arguments when started as an application but not when running scripts

Submitter:  Atri Bhattacharya <badshah400>
Submitted:  Tue 18 Oct 2016 10:20:32 PM UTC
   
 
Category:  None Severity:  3 - Normal
Priority:  5 - Normal Item Group:  None
Status:  Works For Me Assigned to:  None
Originator Name:  Atri Bhattacharya Open/Closed:  * Closed
Release:  * 4.2.0-rc2 Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Sat 22 Oct 2016 05:28:53 PM UTC, comment #4: 

I suggest you read

https://www.gnu.org/software/octave/doc/interpreter/Executable-Octave-Programs.html

which contains a simple example of how to process command line arguments to an Octave program.

Octave scripts do not have arguments. Octave functions do have arguments (using named parameters, nargin, varargin, etc), and Octave programs do have arguments (using argv).

Mike Miller <mtmiller>
Group Member
Fri 21 Oct 2016 09:33:10 PM UTC, comment #3: 

Thanks, Mike! I am sorry, I do indeed see that the behaviour is consistent across versions. Still, I would very much appreciate if you could let me know of a way to distinguish between input arguments passed to the octave command line and when the script is run from inside octave. Clearly nargin and argv aren't helping.

Thanks!

Atri Bhattacharya <badshah400>
Tue 18 Oct 2016 10:43:36 PM UTC, comment #2: 

Thanks for your bug report, but I'm not sure that you're describing a bug rather than a feature or a misunderstanding.

I also don't see any inconsistency between Octave 4.2 and previous versions of Octave wrt nargin and command line arguments. Can you give an example that you believe shows a difference from previous Octave versions?

Yes, running an Octave executable "script" or "program" from the command line, as in


$ ./mytest.m

or

$ octave -qf mytest.m


is slightly different from running a script or function in Octave by name, as in


$ octave
octave:1> mytest

or

$ octave --eval mytest


Mike Miller <mtmiller>
Group Member
Tue 18 Oct 2016 10:27:11 PM UTC, comment #1: 

Sorry, my original discussion got mangled by markup formatting. Here is the latter part of my description:

The results for the various different ways of invoking octave to run mytest.m is as follows:



1. > ./mytest.m
   > 0
2. > octave -q --no-gui -f mytest.m
   > 0
3. > octave-cli -q --no-gui
   octave:1> mytest
    2
   octave:2>


and so on. In the third case, both the '-q' and '--no-gui' are counted as inputs and end up incrementing nargin. When directly running the script, the command-line args are not counted as such.

Atri Bhattacharya <badshah400>
Tue 18 Oct 2016 10:20:32 PM UTC, original submission:  

Octave seems to be counting command-line arguments as inputs (i.e. incrementing nargin) when launched as an application, e.g., not directly running scripts.

For example, consider the following simple script:

mytest.m




#!/usr/bin/octave -qf
# vim: set et ts=2 sw=2 tw=80:

disp(nargin);




The results printed to the screen are different based on how I run this script:

  1. ./mytest.m

  0

  1. octave -qf --no-gui mytest.m

  0

  1. octave-cli -q

  octave:1> mytest
   1
  octave:2>

This inconsistency can cause issue with scripts depending on nargin, as the results become dependent on how octave is invoked to run the script. This seems a new problem with the 4.2.x branch, I have used nargin dependent scripts with octave 4.0.x and this problem never showed up then.

Atri Bhattacharya <badshah400>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by badshah400 (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-10-22 mtmiller Open/ClosedOpen Closed
    2016-10-18 mtmiller StatusNone Works For Me

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code