I have a program which throws StackOverflowException. So the error output is very big and I can't read beginning of output from terminal. How can I watch all program output?
I know that there is something like pagination in terminal. I've googled about it and found advice to use more or less commands.
So I've tried...
java Program | less
But it doesn't work. What am I doing wrong?
Assuming you are using bash4 you can use the |& to concat std error.
java Program |& less
You can redirect the output to a file
java myProgram &>file.log
Then you can tail , head or grep that file.
Use a good IDE (Integrated Development Environment) such as Eclipse. Any decent IDE will have a debugger mode.
Java is a both compiled and interpreted language, which gives it speed and is also easy to debug.
IDE debuggers will walk you through the program execution step by step, which can help you to find errors in your program that you might not otherwise see.
Related
I'm calling vim/gvim from within a Java program to convert a source code containing file into html, as follows: "gvim -c \"set syntax=java\" -c \"TOhtml\" -c \"wq\" -c \"q\" -c \"q\" " + Konst.FPATH + "tmp.txt"
However, for some reason gvim thinks "syntax=java" is a name of a file, and ends up spitting out tons of messages ".syntax=java.swp" found, and more importantly does not apply syntax highlight after all. How to fix this?
EDIT: For some reason, "set syntax=java" is misinterpreted, and gvim opens a file syntax=java" -- exactly this, with a double-quote at the end.
Executing an external program from Java is generally not a good idea, especially if this code run on a web server. It might lead to serious security issues.
What are you trying to do? If your goal is to highlight some Java code, just use a code highlighting library.
I don't know any Java highlighting library, but you can find some good Javascript libs (highlightjs, prismjs, code-prettify, etc.).
I solved this with "gvim -s script.vim" command, where in script.vim I put (!) ":set syntax=java" etc -- yes, starting with ":".
Setup:
I am working on a Java project which invokes some Perl scripts.
Problem:
If I run the Perl script from terminal, it works fine. But when I invoke the same Perl script with same arguments from Java code, it fails. It is an extremely strange and annoying bug.
I am able to debug Perl in Eclipse using EPIC plugin. And of course, I can debug Java code. It would be helpful to debug Java and Perl code in the same debug session in Eclipse, so that I can see whats different happening when the script is invoked via Java code.
Not sure if this is even possible, but if anyone has any idea, please share.
Thanks.
Perl has some remote debugging capabilities, so you can get what you need, I think. I don't use EPIC, so I don't know if you'll be able to do it all within Eclipse.
Set the environment variable named PERLDB_OPTS to have the value RemotePort=<host>:<port>. Then, start Perl with the -d flag. Instead of the debugger trying to interact with standard IO on the invoking terminal, it will attempt to connection to host:port.
Here's a Unix-y example. I've got a Perl script hello.pm and two terminal windows open.
First terminal
$ nc -l 12345
That's started NetCat as a dumb server listening on port 12345. If you don't have a server listening before Perl starts, it won't work.
Second terminal
$ export PERLDB_OPTS=RemotePort=localhost:12345 # set the env variable
$ perl -d hello.pm
Now the script is running. Back on the first terminal, I see
First terminal
main::(hello.pm:1): print "hello\n";
DB<1>
I'm in the Perl debugger and ready to go!
I know that at least the Komodo IDE has support for remote debugging, and there's a Perl Monks post on doing it with Emacs, so you can get something more than the command line even if it's not Eclipse. Good bug hunting!
If I run the Perl script from terminal, it works fine. But when I invoke the same Perl script with same arguments from Java code, it fails.
I suggest that you check that you are running the same version of Perl in the two "contexts"; i.e. when the Perl app is run from the command line and from Java.
If that's not the problem, check the environment variables.
The other approach to solving this problem would be to focus on why the program is going wrong, not on how / why the contexts are different. Look at the evidence that you have, and look at ways to gather more evidence ...
The potential problem with trying to do this using a Perl a debugger (in an IDE or stand-alone) is that you are actually running Perl in third "context" which might be different from either or both of the existing ones.
Using a debugger may work ... or it may leave you even more confused.
I need to write a bash script to compile my java program. I know it's a bit artificial but it is homework. (although I'm not sure the bash script is even marked, just used for the automated marking system)
I only have one java file test.java and the script is to only search its own directory: I tried:
#!/bin/bash
javac test.java
and saved as build.sh, i tried to run this from the terminal as both sh build.sh and bash build.sh both gave me errors. Can anyone offer any help?
included errors:
build.sh: line 1: {rtf1ansiansicpg1252cocoartf1038cocoasubrtf350: command not found
build.sh: line 2: syntax error near unexpected token `}'
build.sh: line 2: `{\fonttbl\f0\fmodern\fcharset0 Courier;\f1\fswiss\fcharset0 Helvetica;}'
It looks like you've saved your script as rich text (RTF), not plain text. Try re-saving it using your favourite plain-text-friendly editor?
Silly question, but what editor did you use to edit your Java program?
It looks like your Java program is in RTF format and not plain ascii.
If you tell me you used Wordpad, I'm going to track you down, fly to your town, come to your work, and slap you silly. DO NOT EVER USE A NON-PROGRAM EDITOR FOR EDITING A PROGRAM.
Sorry for the all capitalizations. I have a bunch of bozos cow-orkers coworkers at my work who think Wordpad and Notepad have been blessed by God himself as the perfect pair of program editors. At least once per week, I'm fixing problems caused by someone using these programs.
If you're on Windows, download Notepad++. If you want to learn a real program editor, try VIM. If you're on Linux or Mac OS X, you already have VIM installed on your system. If you want a more GUI oriented program editor, try downloading JEdit.
Just make sure you use a true program editor the next time you need to edit a program -- even if it's nothing but a two line shell script.
It seems like the editor you're using adds some extra information to the file:
{\fonttbl\f0\fmodern\fcharset0 Courier;\f1\fswiss\fcharset0
Helvetica;}'
what editor are you using? Try opening the file with something simple, like nano, and remove all the extra stuff.
I have a java program that uses ProcessBuilder to call the unix sort command. When I run this code within my IDE (intelliJ) it only takes about a second to sort 500,000 lines. When I package it into an executable jar, and run that from the terminal it takes about 10 seconds. When I run the sort command myself from the terminal, it takes 20 seconds!
Why the vast difference in performance and any way I can get the jar to execute with the same performance? Environment is OSX 10.6.8 and java 1.6.0_26. The bottom of the sort man page says "sort 5.93 November 2004"
The command it is executing is:
sort -t' ' -k5,5f -k4,4f -k1,1n /path/to/imput/file -o /path/to/output/file
Note that when I run sort from the terminal I need to manually escape the tab delimiter and use the argument -t$'\t' instead of the actual tab (which I can pass to ProcessBuilder).
Looking as ps everything seems the same except when run from IDE the sort command has a TTY of ?? instead of ttys000--but from this question I don't think that should make a difference. Perhaps BASH is slowing me down? I am running out of ideas and want to close this 20x performance gap!
I'm going to venture two guesses:
perhaps you are invoking different versions of sort (do a which sort and use the full absolute path to recompare?)
perhaps you are using more complicated locale settings (leading to more complicated character set handling etc.)? Try
export LANG=C
sort -t' ' -k5,5f -k4,4f -k1,1n /input/file -o /output/file
to compare
Have a look at this project: http://code.google.com/p/externalsortinginjava/
Avoid the need of calling external sort entirely.
Noob question, apologies. I'm compiling Java in Windows Vista's command-line and have so many syntax errors that some are being pushed off the top (a lot of 'class, interface or enum expected' errors which leads me to believe it's an obvious syntax mistake early on in the code that I can't spot). Does anyone know how I could get it to display those first errors?
Thanks in advance for the help.
You have several options:
route stdout and stderr to a file:
javac [whatever] > file.out 2>&1
use an IDE
increase the 'height' of your command console's buffer in "Properties/Layout/Screen Buffer Size" - I routinely set this setting to 6000 so I can scroll back a long ways...
Try increasing the buffer size for your command-prompt. Read more here:
http://www.cs.princeton.edu/introcs/15inout/windows-cmd.html
you can
1 - as Matt says Use an IDE, will make your life much easier. there are plenty of good ones.
2 - as Ben said you can increase the buffer but even if you do so you still run the chance of loosing some messages.
3 - you can pipe the output through more ex :
javac SomeClass.java | more
However this will make your compiling much longer as it will wait for you to scroll pages
4 - redirect the messages to a file ex :
javac SomeClass.java > compileLog.txt 2>&1
More on redirection for CMD here. This way you can view the messages without worrying that you missed any or without being constrained to the command line window. Search through them etc.
Use an IDE so you 1) don't have to scroll for pages to find errors 2) can jump straight to the line with the error.
Redirect your ouput for the command's errors to a text file and open it on notepad
ex: suppoing Test.java is your program
> javac Test.java 2>errs.txt
> notepad errs.txt