-1

I'm working on a project that requires the use of a test framework called Appium in Java. The Appium library is attempting to run the following script on my machine to find out where my NodeJS install is located (not important that it is node):

#!bin/sh
OUTPUT="$(npm root -g)"
echo "${OUTPUT}"
exit

This script is executed during my JUnit unit tests in Java explicitly with bash. See this link to see the code that Appium uses to run the script. On my system, if I execute this from a shell (using zsh, bash, or sh), I get the following output:

/home/me/node-v8.9.0-linux-x64/lib/node_modules

Great. For some reason, when that same script is running in the environment that is set up by my IDE (IntelliJ), this is the output:

/home/me/node-v8.9.0-linux-x64/lib/node_modules

[H[2J

Regardless of whether or not this was a good idea on the part of Appium, its breaking because of the extra \r\r\n[H[2J. I usually launch IntelliJ through a program called GnomeDO on Ubuntu MATE. After seeing that my $PATH in IntelliJ was different at run time than what I expected, I closed it out and launched it form my shell instead. The $PATH was right and the trailing output stopped.

What can be different about launching an application from my desktop environment in Linux and launching it from my shell that would lead to trailing non-readable characters?

  • 2
    Those characters look like the control character sequence for moving cursor to top left of a terminal window and clearing the screen. Try echo -e '\e[H\e[2J' from a shell and you'll see what I mean. Don't know if that will help identify the cause but... – B Layer Nov 5 '17 at 3:09
  • 1
    That should probably read "escape sequence" rather than "control character sequence" but you get my drift. en.wikipedia.org/wiki/Escape_sequence – B Layer Nov 5 '17 at 3:20
  • Where is that displaying? Intellij is opening a terminal window of some kind? Is it a new window or embedded in the IDE? I see a few mentions about some Gnome terminals not handling some escape sequences correctly so perhaps when launching with DO you get one of those terminals instead of one that handles them correctly. – B Layer Nov 5 '17 at 3:33
  • Based on the new information in your edit Gnome DO is not relevant at all. But parts of my answer still have relevance. I'd like to hear whether a different terminal is used when running the script directly vs when Intellij launches it. If they are the same then what happens when you execute the echo command I specified in that terminal? – B Layer Nov 5 '17 at 23:26
  • @BLayer As for "where is that displaying", all of this information came from debugging unit tests in IntelliJ's debugger. I had to actually step through line by line, see the output of the Appium shell execution saved as a Java variable, see .trim() do nothing because it didn't end in whitespace, etc. – Anthony Naddeo Nov 6 '17 at 2:10
1

Note: I've been theorizing in the comments and this captures those thoughts and a HIGHLY speculative conclusion.

The funky characters look suspiciously like the escape sequence that moves the cursor to the top (top-left?) of a terminal and then clears the screen. You can see this in action by doing this in a shell: echo -e '\e[H\e[2J'.

I did a little searching and found a few references to Gnome terminals having incomplete support for escape sequences and for the problem sequences characters looking just like ours (e.g. [H) are displayed

Combining those two facts leads to a theory:

  1. Intellij emits some escape sequences upon opening a terminal window to clean the window up including \e[H\e[2J.
  2. Gnome DO sets up an environment that points to a particular terminal type and this is different from the terminal you use normally.
  3. Intellij launches this terminal when it is launched from DO, emits escape sequences, then runs your script.

Ah but why does the escape sequence come after the output of the script. That does not necessarily mean that it was printed after the script output was printed. There could be other escape sequences emitted by Intellij that worked and they could have moved the cursor in such a way to make the lines appear seemingly out of sequence.

Again this is extreme speculation made without having all the facts...but see if you can find a Gnome terminal on your system that doesn't handle the echo command above or otherwise check my guess.

  • The world wants you to clean your screen. Also, read that script carefully. (-: – JdeBP Nov 5 '17 at 9:58
  • @JdeBP Afraid I'm not catching your meaning...either with the linked answer or your comment about the script. The script isn't really important for my theory/guess. What's important is that some escape chars are being processed correctly in one case and not in the other case. If you've identified some important data points please clarify. – B Layer Nov 5 '17 at 13:16
  • I just updated the second paragraph with a link to the source code that Appium uses to execute the script. It happens each time I run a unit test so it isn't an IDE startup thing. They also explicitly execute the script with bash (despite having put the sh shebang...). I do find that escape sequence very interesting though, I didn't know that. That's the kind of thing I was hoping to learn from this post too so thank you. – Anthony Naddeo Nov 5 '17 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.