I am trying to use the "Program Arguments" field in Eclipse (using java, on a mac), but whenever I enter an argument, it treats the argument like a file. I'm getting the same error no matter what. For example, if I input AL into the command line, I get the following error:
I/O exception while reading: ......./AL (No such file or directory)
I'm assuming I didn't set something up right and I was wondering how to set the command line up? I have made sure that I have the correct file, the correct method, and the pathway (the ....'s) is valid. Not really sure why this isn't working and having a hard time finding answers online.
EDIT: I added a picture of the full program and output that I am getting. For the arguments I put an "a" followed by a return key and a "b".
Related
How to make sure that the name of the input file (input .txt)is not written in the program
but it could be changed using these type arguments (-Dinputfile)
I tried to figure it out myself, but nothing worked, I hope for your help...
I am not a programmer so maybe my question seem very fundamental.
I have to run the the code in the link below to get an output file:
https://github.com/matsim-org/pt2matsim/blob/master/src/main/java/org/matsim/pt2matsim/run/Gtfs2TransitSchedule.java
This code gets an input (a folder containing some text files related to open street map) and also in the code I have to specify a coordinate system (in my case is EPSG:3857) and I think also I have to specify a path fot the output file.
Unfotunately I don't know how I should specify the input file and also how I should edit my desired coordinate system. Also I have to mention these are written as args[0], args[1], args[2] and args[4] in the code.
in IntelliJ, go to Run, edit configuration,
in Program arguments you have to write the argumnet values or paths and seperate them by space
for example if my first argument is a zip folder in Drive C and my second argument is a date then I should write like below:
C://Folder//A.zip 2022.09.27
I am working on a existing Java EE based application .
Somehow the functionality is not working written by them .
When i found out the logs in Linux server i found out this Exception there
Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
at com.cyber.EasyOptions.view(EasyOptions.java:2054)
What does this mean exactly ??
I guess there is a class named EasyOptions and in that there is a method view and inside it there is this Exception occuring ??
This particular class EasyOptions is present inside a jar file in our code .
I am using JD-GUI decompiler and when navigated to this particualr jar , and saw this class EasyOptions , inside view method there is no such line (2054)
so dont know we can match the line numbers this way or not ??
I guess we cant match line numbers this way , my questions how can we trace out the exact line of error ??
guess there is a class named EasyOptions and in that there is a method view and inside it there is this Exception occuring ??
That's correct.
I am using JD-GUI decompiler and when navigated to this particualr jar , and saw this class EasyOptions , inside view method there is no such line (2054)
The line number only makes sense in the context of the original source code. The decompiled code isn't identical to the original and will have different line numbering.
how can we trace out the exact line of error
Without the original source code it's going to be tricky. One way to narrow down the possibilities is to look through the decompiled code for EasyOptions.view(), looking for places where an array is being accessed.
I have a class (called LogCopy) I've written which when I run it in Eclipse with the 4 parameters it's supposed to have, in the correct format, surprise, surprise, runs perfectly fine. The trouble is, I need to .jar it up to put onto a live system & that's where it gets squirly. The parameters are 2 datetime stamps & 2 filenames. It's being developed & executed on a Windows system so the parameters I've supplied to test with are:
2011-03-20|10:21:20 2011-03-20|10:21:21 F:\somepath\logfile.txt F:\somepath\logfileoutput.txt
Now, putting those into a Run Configuration in Eclipse gets the desired response. If I remove a parameter or put in a value that isn't a valid date or a readable input file or a locked output file, it throws exceptions as I've set it up to do, all well & good. But when I jar it up using maven, and run it with the 4 parms as they're supposed to be I get the cryptic
The filename, directory name, or volume label syntax is incorrect
Strangely though I still get the expected error messages when I deliberately mess up the parameters, so
java -jar LogCopy-0.0.1-SNAPSHOT-jar-with-dependencies.jar parm1 parm2 parm3 parm4
gets an error log entry for each thing that's wrong about the parameters - that the dates aren't valid dates, the filenames aren't referring to files that can be used, and a little precis of the command's syntax so the user can correct what they've entered.
How come the valid filenames are giving this weird error message? I've tried entering the filenames in various formats, using forward slashes, backslashes, escaped backslashes, all sorts, but they all give the same (non programmed by me) error message. What gives?
I sussed it - & you're all going to think I've been a total noob about this & you'd be right. One of those "D'OH!!" moments. Turns out the parms only work properly if passed in as strings in double quotes, so:
java -jar LogCopy.jar "2011-05-04|10:05:23" "2011-05-04|10:05:26" "C:\dir\fromfile.txt" "C:\dir2\tofile.txt"
works, while without the double quotes Java mis-parses the parameters & appears to take part of the date as a filename.
I have the Java code below running on Unix (both AIX and Linux), but it doesn't work. If I run this code the file q1.01 is not compressed, and I don't get any exceptions thrown (The file q1.01 exists, and I expect to find the file q1.01.Z after the command runs.) At the command prompt if I type "which compress" it reports back with "/usr/bin/compress". If I type the command "/usr/bin/compress q1.01" at the Unix prompt it works fine. Any ideas on what might be wrong?
String cmd = "/usr/bin/compress q1.01";
Runtime.getRuntime().exec(cmd);
[Later edit: the problem was in the initial description; the OP was passing a wildcard and not q.01. So my answer below is wrong, except for the part in bold. I'm leaving it so the comments after it will make sense.]
It's trying to run /usr/bin/compress as the program name without arguments.
There are many forms of the Runtime.exec() method. You're using the .exec(String) version, which just takes the executable. Instead, you need to use the .exec(String[]) array version, which takes the executable in String[0] and the parameters in String[1..].
.exec() wants a String array for passing arguments.
Try
String[] cmd = new String[] { "/usr/bin/compress", "q1.01" };
Runtime.getRuntime().exec(cmd);
Note that .exec does not call the local command shell. That means we have to do, among other things, wildcard expansion and even some argument parsing before calling .exec(). This is why you can't just pass it your full command line.
There were a couple of problems. One was that I had tried using wildcards, and since the shell isn't invoked they weren't being expanded. The other problem was that I had created very small test files like this: "echo 'abc' >q1.01". This file was so small that compress couldn't compress it any further and so left it alone. (Stupidly, I think when I typed in the command at the shell I used a different filename, which did compress.)
Thanks everyone for the answers. It did help!
You probably need to use an absolute path to the file. Capture the output though, to see what the problem is - see this page for info on how to do that.
This site may be able to provide some clues.
If the process input stream is null, I suspect that Java wasn't even able to spawn the subprocess. What does Process#exitValue() return?
I'd recommend using strace to see what actually happens on the system-call level. The actual exec() arguments and return code would be especially interesting to see.