I'm running ubuntu 14.10, and I've created and saved a model through the GUI. Now I have some test data I'd like to run from the command line. This works fine, as long as I don't try and pass any classifier specific options. When I do, I receive a "invalid option" message.
For example, the following works:
java -Xmx1g -cp /usr/share/java/weka.jar weka.classifiers.lazy.IBk -l ibk1-full.model -T testdata.arff
However, the following does not:
java -Xmx1g -cp /usr/share/java/weka.jar weka.classifiers.lazy.IBk -l ibk1-full.model -T testdata.arff -K 3
Weka exception: Illegal options: -K 3
General options:
-h or -help
Output help information.
-synopsis or -info
...
How does one pass command line arguments to the classifier?
Additional question: are the default arguments used when generating the model saved with the model, so that when someone uses '-l foo.model' to load it from the command line, one does not need to specify the rest of the arguments on the command line? The weka CLI primer documentation is unclear on this.
Note: I know IBk isn't exactly a model, per-se, but its illustrative of every classifier I try.
The -K parameter does not appear to work when a classifier is being loaded, but rather when training the model from the command prompt. This is likely due to the fact that the kNN model is already trained with, say, k=1, so changing k would change the model that has already been generated.
If you use the parameters -K, -t and -T, you should be able to generate a new model with the desired k on a nominated training set and evaluated on given testing data.
I don't believe the issue you have is with the command line arguments (you're doing it right!), but rather that the argument is invalid in your given situation.
Additional Question: The parameters of the model that was trained are not likely required as they were used for training, which was completed before being saved. Other parameters will still be required (like testing data for evaluation).
Hope this Helps!
Related
Can arguments for a class be passed the following way?
java cs123.Learn -mode train -algorithm even_odd -model_file speech.even_odd.model -data speech.train -task classification
Here, cs123 is the package within which the different java files and their compiled versions are located. I have already compiled the .java files using the following command
javac -cp commons-cli-1.2.jar cs123\*.java
To make things clear, the structure of the .java and .jar files are
lib
|--cs362
| |--all the java files including Learn.java
|--commons-cli-1.2.jar
I am running the command prompt from the lib folder. What worries me is that from java documentation and other sources the format for passing arguments is simply an array of strings and for options it can be seen from java documentation too. Using the above run time java execution, I get the
java.lang.ClassNotFoundException: org.apache.commons.cli.OptionBuilder
but if I execute,
java -cp commons-cli-1.2.jar cs123.Learn -mode train -algorithm even_odd -model_file speech.even_odd.model -data speech.train -task classification
I get the following error
Unrecognized option: -mode
Error: Could not create the Java Virtual Machine
Error: A fatal exception has occured. Program will exit.
I understand that java tries to associate anything with a - associated with it as a predefined option, -mode not being the one it recognizes. but at the same time the .jar file is there to do it's job. For research purposes, the commons-cli-1.2.jar file is associated with several methods, two of them being commons/cli/Option and commons/cli/OptionBuilder.
I am having to do this because the instruction is to run the program using
java cs123.Learn -mode train -algorithm even_odd -model_file speech.even_odd.model -data speech.train -task classification
I have made a test with commons-cli with the -mode in option. It compile and run as expected. So I can make sure with you that you can using that option.
I am standing in java folder to run the command, my folder structure:
java
|--upwork
| |--Main.java
|--commos-cli-1.2.jar
For your problem: I see that your command only point classpath to commons-cli lib and not point to the location of your package. Refer to this answer your command should start with: java -cp .;commons-cli-1.2.jar ...
If this does not help, please upload your code to get help or you can create a simple test like mine to check this out.
Can arguments for a class be passed the following way?
I don't think so for the good reason that what you're trying to pass with your "-naming" are program arguments. Program arguments are retrieved in your app with the String[] args of your main and in Java you don't have String index in arrays.
If you want to achieve what you want, you could still do it but you would have to implement the logic in your program. Firstly, you would need to get all the args in your program and then implement the logic by building a map for example and process this map.
As an example, you could say that if any argument (i.e args[0]) starts by "-" it means that it's a key for your map and that the following argument (i.e. args[1]) is the associated value.
Edit: I haven't used commons-cli and I may be completely wrong but from a quick research online, I think the library is offering you the logic to build commands to execute in command line once your application is running.
After running into an issue on executing some queries as strings in Java for postgres, I went using string arrays, which solved my existing issues.
After the switch I am now having an issue with pg_dump, but not with pg_restore.
When I supply my method with the following array:
[time, ./pg_dump, -U, lehigh, -d, lehigh, -Fc, data/completedDb.dump]
I get the following error:
pg_dump: too many command-line arguments (first is
"data/completedDb.dump")
ProcessBuilder produces the following for my execution:
time ./pg_dump -U lehigh -d lehigh -Fc data/completedDb.dump
And it works fine when I add the output arrow, and remove the data folder, on the command line.
time ./pg_dump -U lehigh -d lehigh -Fc > completedDb.dump
I'm running this through eclipse, in Java on a postgres database, using :
Runtime.getRuntime().exec();
I've tried using Process.start() but got the same errors, so I'm totally dumbfounded at what I'm doing wrong.
Prior to this change, pg_dump was being executed properly as a single string. I don't want to go back to that method as I want to maintain consistency, but I also want to figure out what I'm doing wrong here.
You should use -f before the output file name, since by default pg_dump outputs to stdout.
Try
[time, ./pg_dump, -U, lehigh, -d, lehigh, -Fc, -f, data/completedDb.dump]
I'd like to know how it is started. What is the command to start this java process ? What I mean is I have one running java process, and I'd like to know the command to start it, such as what is the main class and what is the arguments, etc.
Any tool for that ? Thanks
There is a command line tool that comes with the JDK: jps, that will give you the list of java processes being run at the moment you execute the command, the arguments given to the method main and the parameters used for the JVM. Try this:
path\to\jdk\bin\jps -m -l -v
It won't give you the exact command used to start the process, but it will give you a hint of how to "rebuild" that command.
For more info, if you are on a decent distro of linux, try man jps or if you are on Windows, see the Oracle documentation about jps.
Your question wasn't clear. If you are looking to find the command that launched this process than you can look at the property sun.java.command. This will give you the main class name and arguments passed to it. java.class.path property gives you the class path. You can get the arguments passed to the java command itself by using ManagementFactory.getRuntimeMXBean().getInputArguments() method. Using all these you should be able to reconstruct the java command.
If you use Windows, you can use the Taskmanager, go to the Process/Details Tab, where you can see the PID for each Process. There you can add a column for the command line (e.g. in German its "Befehlszeile", i'm not sure how that column is labeled in English).
Then just look at the java.exe/javaw.exe Processes.
You could also use the alternative Taskmanager from Microsoft, Process Explorer, afaik there you can just click right on a process and select details.
Sry for bringing this question again as its most common solution would be to include path.. I am trying to implement a class and after implementation it displays the following
java -classpath java-getopt-1.0.8.jar;3dm-0.1.0.jar;xerces.jar tdm.
tool.TreeDiffMerge
3DM XML Tree Differencing and Merging Tool version 0.1.0 build 0.1.0-2006.02.07.
12.26.44
Usage: 3dm [options] {-m base branch1 branch2|-d base branch1 |-p base patch} [o
utfile]
Use the -m (or --merge) option to merge the files base, branch1 and branch2
Use the -d (or --diff) option to diff the files base and branch1
Use the -p (or --patch) option to patch the file base with the file patch
The options are:
-e, --editlog[=logfile]
Log edit operations to logfile, default edit.log
-c, --copythreshold=bytes
Threshold for considering a duplicate structure to be a copy. Default value i
s 128 bytes
Now a exe is not created ..Do u know wht the pblm might be.. Or can u suggest ways to solve this issue ?
The output doesn't seem to have anything to do with your question title.
It's clear from the message that you aren't invoking the tool properly, and need to provide command-line arguments to the tool in order to tell it what to do. E.g.:
java -classpath java-getopt-1.0.8.jar;3dm-0.1.0.jar;xerces.jar tdm.tool.TreeDiffMerge -p base patch
If you've implemented your own main class and want to invoke it, you'll need to provide the classname on the command line instead of tdm.tool.TreeDiffMerge. (And if you want an exe to be created, hopefully your class does this because Java has absolutely nothing to do with creating exes inherently.)
This is an extremely strange situation, but I just cannot point out what I'm doing wrong.
I'm executing a big bunch of SQL scripts (table creation scripts, mostly). They are executed through Java, using sqlcmd. Here's the sqlcmd command I use.
sqlcmd -m 11 -S SERVER -d DB -U USER -P PASS -r0 -i "SCRIPT.sql" 2> "ERRORS.log" 1> NULL
Note: I use the -r0 and redirects to make sure only errors go into the log file. I chuck out all STDOUTs.
Now I execute this command in Java, using getRuntime.exec(), like this.
Runtime.getRuntime().gc();
strCmd = "cmd /c sqlcmd -m 11 -S SERVER -d DB -U USER -P PASS -r0 -i \"SCRIPT.sql\" 2> \"ERRORS.log\" 1> NULL"
Process proc = Runtime.getRuntime().exec(strCmd);
proc.waitFor();
Note: I use cmd /c, so that the command runs in its own shell and exits gracefully. Also, this helps in immediately reading the error log to look for errors.
The Problem!
This command works perfectly when run by hand on the command prompt (i.e. the tables are getting created as intended). However, when executed through Java as shown, the scripts are run, and and there are no errors, no exceptions, nothing in the logs. But, when checking in SSMS, the tables aren't there!
Where do I even begin debugging this issue?
UPDATE: I'M A MORON
The return value from the getRuntime().exec method is 1. It should be 0, which denotes normal execution.
Any pointers on how to fix this?
UPDATE 2
I've looked at the process' ErrorStream, and this is what it has.
Sqlcmd: Error: Error occurred while opening or operating on file 2>
(Reason: The filename, directory name, or volume label syntax is
incorrect).
Looks like the path I'm passing is wrong. The error log goes into my profile directory, which is C:\Documents and Settings\my_username. Do the spaces in the path matter? I'm anyways double-quoting them!
Have a look at the exec method with an string array as parameter:
java.lang.Runtime.exec(String[] cmdArray)
The JavaDoc for this method says:
Executes the specified command and arguments in a separate process.
So, the first item in the array is the command and all of your arguments are appended to the array, e. g.,
Runtime.getRuntime().exec(new String[] {"cmd", "/c", "sqlcmd ... "});
After looking at your comment and the implementation of exec(String) it seems to be, that the exec method recognizes the pipe operator > as an argument to cmd, because exec(String) splits the command string to an array using whitespaces as seperators.
I don't have privs to post comments - which is what this is - but what if you try putting in a bogus user id for the DB? Does that cause a different execution path? Will that give you a Java error? Or an Auth error in your DB? Also, def tweak the user, not the password and learn from my experience that if you tweak the password that's a great way to get an account locked out!
The other thing - and this may be a shot in the dark - but what are the JRE and driver you're using? I believe there's a known issue with JRE 1.6.0.29 and the sqljdbc4 JAR. I have more details on this, but I'll have to post the link once I get to work.
Edit:
I know it's been established that the JRE/sqljdbc combo isn't your issue, but if folks search and find this, here is the link I spoke of above:
Driver.getConnection hangs using SQLServer driver and Java 1.6.0_29
First enable log/view commands output (since exec() returns 1), which would point out possible cause of the issue.
Use proc.getInputStream() and print the contents to a file or console.