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

System.out.print(">") not work #159

Open
quantrpeter opened this issue Jul 11, 2020 · 7 comments
Open

System.out.print(">") not work #159

quantrpeter opened this issue Jul 11, 2020 · 7 comments

Comments

@quantrpeter
Copy link

Hi
System.out.print(">") not work, event i added System.out.flush(). The ">" never appear on screen. I am not sure Scanner::nextLine() affect it. Below is my code:

	private void run() {
		System.out.println("started");
		Scanner in = new Scanner(System.in);
		String command;
		System.out.print(">");
		while (!(command = in.nextLine()).equals("q")) {
		}
	}

thanks
Peter

@quantrpeter
Copy link
Author

this is a stupid fix, but at least it works

image

@sruebner
Copy link

sruebner commented Dec 8, 2020

I'm having the same problem. I wanted to write an interactive command line program, but this is so annoying. Even if I manually flush System.out, it does not work until I send a newline character. When I build the project and execute it from the JAR-file, everything works as expected.

Would be nice to at least get some feedback.

@ShadowXBoss696
Copy link

ShadowXBoss696 commented Jan 9, 2021

Same problem here .... Even replaced System.out with AnsiConsole.out ( from Jansi )...
But nothing seems to work ...

Also, I have another problem i.e., after the System.out.print('>> ') call followed by System.console().readLine(), no typed charecters gets displayed until I press enter .... After that the typed charecters followed by printed string ( '>> ') gets printed to the display ....

Please provide some feedback ...

@YoungFrog
Copy link

I had the same problem. A workaround for me was to use an older version of maven (3.3.9).
I think this is https://issues.apache.org/jira/browse/MNG-6239
IIUC the fix is to use jansi 2.0.1 and apache/maven#401 is already merged, so we're only waiting for a release.

Anyway I don't think this is related to exec-maven-plugin at all

@quantrpeter
Copy link
Author

@YoungFrog really sad

@Atrament666
Copy link

Same problem here, after some trials and errors I found that the problem seems to be in the 'exec:exec' goal because when using exec:java goal it works like a charm.

Simple example to test it on:

public static void main(String[] args) {
        System.out.print("Enter your name: ");
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();
        System.out.println("Your name is: " + name);
}

When run on command line with exec:exec goal, the prompt 'Enter your name' doesn't show up, until you enter something and only then it appears together with the message 'Your name is ...' The output looks like this (my name is Atrament):

Atrament
Enter your name: Your name is: Atrament

When using the goal exec:java, the prompt shows up and the output looks like expected:

Enter your name: Atrament
Your name is: Atrament

@FlorianCassayre
Copy link

Very unfortunate, I was testing this plugin with some interactive bash scripts and the prompts simply don't show up:

read -p "Enter something: "

Prints a blank line.

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

No branches or pull requests

6 participants