Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to pipe to standard input #1037

Open
rj93 opened this issue Apr 1, 2024 · 3 comments
Open

How to pipe to standard input #1037

rj93 opened this issue Apr 1, 2024 · 3 comments
Labels
type/enhancement Is an enhancement request

Comments

@rj93
Copy link

rj93 commented Apr 1, 2024

Hi,

I am trying to find out how to pipe to a commands standard input.

Taking the quick start example:

java -jar demo-0.0.1-SNAPSHOT.jar hello-world boot

I would like to be able to achieve:

echo "boot" | java -jar demo-0.0.1-SNAPSHOT.jar hello-world
@github-actions github-actions bot added the status/need-triage Team needs to triage and take a first look label Apr 1, 2024
@jvalkeal jvalkeal added type/enhancement Is an enhancement request and removed status/need-triage Team needs to triage and take a first look labels Apr 2, 2024
@jvalkeal
Copy link
Contributor

jvalkeal commented Apr 2, 2024

Unfortunately this is not yet supported. There's been a recent work in JLine making process input/output easier to handle so hopefully we're able to implement these features.

@rj93
Copy link
Author

rj93 commented Apr 4, 2024

Forgive my naivety, but why couldn't a simple InputStreamReader be used to read in from the pipe?

It is fairly safe to assume that when using a pipe a program would be ran in not interactive mode, so could the following potentially be updated to read from System.in and then parse the commands?

List<String> commands = this.commandsFromInputArgs.apply(args);

I've got a crude local test and it works with the quickstart example:

public void run(ApplicationArguments args) throws Exception {
	shellContext.setInteractionMode(InteractionMode.NONINTERACTIVE);
	args = mergePipeAndArgs(args);
	List<String> commands = this.commandsFromInputArgs.apply(args);
        ...
}

private ApplicationArguments mergePipeAndArgs(ApplicationArguments args) {
	BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
	String[] mergedArgs = Stream.concat(Arrays.stream(args.getSourceArgs()), stdin.lines())
			.toArray(String[]::new);
	return new DefaultApplicationArguments(mergedArgs);
}

@rj93
Copy link
Author

rj93 commented Apr 5, 2024

Did a bit more playing around with the above and it doesn't play very nice piping file contents to it, for example YAML files get parsed broken because of some post processing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement Is an enhancement request
Projects
None yet
Development

No branches or pull requests

2 participants