Piping to Spidermonkey isn't working correctly
I've installed the latest version of Spidermonkey (JavaScript-C 1.8.5+ 2011-04-16) and have noticed a strange quirk that you might k开发者_如何学JAVAnow the answer to.
In the past, if I did:
echo -n "print('hi');"
The result would come back as:
js> hi
However, now when I run that very same command, the return output I get is:
js> print('hi');
hi
js>
As you can see there are 3 lines of output, rather than just 1.
This normally wouldn't be an issue, but I'm working with a particular CMS which isn't handling this exception and so just errors out.
Is there a workaround? Should I just install an older version?
P.S. I understand Spidermonkey has the option of "e" (i.e. js -e "print('hi')") to run inline code, but once again the CMS I'm using doesn't work that way :\
Looks like they have changed the way spidermonkey works in the newest versions. To overcome this issue in Ubuntu 10+ follow these instructions:
sudo add-apt-repository ppa:launchpad/ppa
sudo apt-get update
sudo apt-get install spidermonkey-bin
Now if you run:
echo -n "print('hi');" | js
It will print:
hi
+1 for Anton Babushkin's answer, but the newest SpiderMonkey command line option parser actually a subtle distinction here:
$ echo -n "print('hi');" | ./js
js> print('hi');
hi
js>
$ echo -n "print('hi');" | ./js -
hi
I rewrote the option parser only a few months ago so this would have to be with an up to date version.
精彩评论