bugGNU Octave - Bugs: bug #53412, KBHIT does not detect anything...

 
 

bug #53412: KBHIT does not detect anything from command line, nor does it error out.

Submitter:  deego <deego>
Submitted:  Thu 22 Mar 2018 12:05:36 AM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  None
Originator Name:  deego Open/Closed:  * Closed
Release:  * dev Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 25 Apr 2018 08:10:35 PM UTC, comment #4: 

I think the purpose of that check was to avoid trouble if Octave was reading a script from stdin.  But if Octave is invoked with


octave script.m  ## [1]


instead of something like


octave < script.m  ## [2]


or


cat script.m | octave  ## [3]


then I don't see why kbhit shouldn't work.  And, if I disable the check entirely, currently Octave will work properly for [1] above, and [2] and [3] will just return an empty string when kbhit is executed.

Even for something like


cat | octave


if I type kbhit<RET>, Octave will wait for input, accept a single character, and continue.  So I don't see a good reason to keep the interactive check.

I pushed the following changeset on stable:

http://hg.savannah.gnu.org/hgweb/octave/rev/10ec5795bd06

John W. Eaton <jwe>
Group administrator
Wed 25 Apr 2018 01:26:40 AM UTC, comment #3: 

I wish to reiterate that input() and pause(3) and pause() are able to detect user input from a command line script.

Thus, there is some kind of connection present to the console/terminal. But, unlike input and pause, kbhit doesn't does not seem to utilize that facility.

deego <deego>
Sun 08 Apr 2018 10:48:15 PM UTC, comment #2: 

See bug #48541. I don't have a reason or justification for this, but Octave's kbhit intentionally returns an empty string when Octave is not running interactively.

Mike Miller <mtmiller>
Group Member
Thu 22 Mar 2018 12:11:16 AM UTC, comment #1: 

Sorry, by commandline, I meant this invocation:
 
octave-cli script.m

(not --eval)

deego <deego>
Thu 22 Mar 2018 12:05:36 AM UTC, original submission:  

kbhit does not work from command line, nor does it error out.

## From commandline, things like input() work and read the input.
## When called from commandline, 'kbhit' does NOT appear to work at all! (as illustrated below).
## octave --eval script.m  where script contains the code below.

for ii=1:10;
  disp("Waiting 3 secs to read keypress.");
  pause(5);
  kk = kbhit(1);
  NumKK = numel(kk)  ## Always returns 0 even if you press a key.
endfor

 

## Furthermore, if we wanted to work around it, we'd need to know from a running octave whether we are being run from commandline, but there seems to be no way to know. That is:


## From a crontab, at least kbhit errors out when called, so that we can work around it. try; kbhit(1); catch [tells us that we are not interactive, and use something else.]

## But, from commandline, the above try catch does not fail either.


## If kbhit() won't work from command line, is there a way for a running program to know that it won't work? (so that it may work around it)..

## tried this on 4.2.2 on debian stable.


deego <deego>

 

(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 rik5 (Updated the item)
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by deego (Submitted the item)
  • -email is unavailable- added by deego
  •  

    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 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-09-19 mtmiller Carbon-CopyRemoved 80942 -
    2018-07-28 rik5 StatusReady For Test Fixed
        Open/ClosedOpen Closed
    2018-04-25 jwe StatusConfirmed Ready For Test
        Release4.2.2 dev
    2018-04-08 mtmiller StatusNone Confirmed
    2018-03-22 deego Carbon-Copy- Added -email is unavailable-

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code