Strange / broken mapping of input to arguments in command shell

Project:JNode Core
Component:Code
Category:bug report
Priority:normal
Assigned:Stephen Crawley
Status:closed
Description

There is a dubious piece of code in the threaded / proclet command invokers that (I think) results in some most unexpected behavior in the current command shell.

Here's the snippet from AsyncCommandInvoker.java I'm talking about:

if (nextInputStream != null)
    inputStream = nextInputStream;

CommandLine commandLine = null;

if (inputStream.available() > 0) {
    // FIXME we shouldn't do this. It consumes keyboard typeahead
    // that should be delivered to the command's standard input!!
    commandLine = new CommandLine(inputStream);
} else {
    commandLine = cmdLine.getRemainder();
}

commandLine.setOutFileName(cmdLine.getOutFileName());
...

The problem is the bold section. If you examine the context, and the method called, it seems that the invoker is reading anything on the input stream, parsing it into arguments and using it to replace the user-supplied arguments. For a simple command, the effect is that any type-ahead will cause the command's arguments to be replaced. For a pipeline, the first command's output will be turned into arguments for the second command. This behavior is unexpected and (IMO) incorrect in both cases.

I'm working on a replacement of the built-in thread / proclet mode interpretter that (for example) supports '<' and treats '|' in the UNIX way; i.e. without creating intermediate files. However, this particular brokenness is egregious and needs to be fixed right away. (For the record, the "FIXME" comment is mine, but the code predates my changes to the shell.)

The attached patch (against the latest rev) gets rid of the unwanted behavior.

AttachmentSize
issues_656.64 KB

#1

Status:active» closed

It looks like I "missed the boat" with this patch.

You may as well hold off applying it. I'm working on a larger scale patch that fixes / improves a lot more in the existing CommandShell, CommandLine and CommandInvoker code. It should be ready in a few days.

Appetizer: '<' will be supported in the default shell, and '|' will be executed using PipeStreams. (Currently, commands are executed one at a time, and data is passed using temporary files.)

#2

It turns out that I fixed this long ago. Closing issue.