How to run setup.exe file using java - java

I am developing an java application from which I have to run xyz_setup.exe installer. I tried the following code
String command = "C:\\xyz_setup.exe";
Runtime.getRuntime().exec(command);`
But it was throwing the following error
java.io.IOException: Cannot run program "C:\Users\NewtonApples\Downloads\idman614.exe": CreateProcess error=740, The requested operation requires elevation
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
at java.lang.Runtime.exec(Runtime.java:615)
at java.lang.Runtime.exec(Runtime.java:448)
at java.lang.Runtime.exec(Runtime.java:345)
at upendra.OpenExternalApplication.main(OpenExternalApplication.java:19)
Caused by: java.io.IOException: CreateProcess error=740, The requested operation requires elevation
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:189)
at java.lang.ProcessImpl.start(ProcessImpl.java:133)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1021)
... 4 more
Can any one suggest me how to do this?

Java (or likely any other process which uses CreateProcess system call directly) is not good with executables requiring access elevation.
You can get around that by executing your program via shell:
String command = "C:\\setup.exe";
Runtime.getRuntime().exec("cmd /c "+command);

Related

EMR-4.2.0 Error during running of custom jar (command-runner)

I am running sqoop installation script in AWS - EMR-4.2.0 Version, followed this documentation.
After created cluster (at Steps), I have submitted my sqoop script as an arguments and s3://elasticmapreduce/libs/script-runner/script-runner.jar/ command-runner.jar as a jar file, but getting error like this. Can you help me pls what is the cause and problem?
Error:
Exception in thread "main" java.lang.RuntimeException: java.io.IOException: Cannot run program "s3://bmsgcm/spark/install-sqoop.sh" (in directory "."): error=2, No such file or directory
at com.amazonaws.emr.command.runner.ProcessRunner.exec(ProcessRunner.java:139)
at com.amazonaws.emr.command.runner.CommandRunner.main(CommandRunner.java:13)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
Caused by: java.io.IOException: Cannot run program "s3://bmsgcm/spark/install-sqoop.sh" (in directory "."): error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1047)
at com.amazonaws.emr.command.runner.ProcessRunner.exec(ProcessRunner.java:92)
... 7 more
Caused by: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:187)
at java.lang.ProcessImpl.start(ProcessImpl.java:130)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1028)
... 8 more
command-runner.jar can only read local files. You can add a bootstrap script to copy files from S3 to local file system.
Piggybox is correct. Unlike script-runner.jar that was used on the 2.x and 3.x EMR AMIs, command-runner.jar can only run local commands. A bootstrap script is the best way to do this.
For instance, if you have a few spark drivers on S3, and you have a shell script (also on S3) to copy them to the master node for later use in a job flow step with spark-submit, then you might have had a step like this:
Steps=[
{
'Name': 'Install My Spark Drivers',
'ActionOnFailure':'TERMINATE_JOB_FLOW',
'HadoopJarStep':
'Jar': 's3://us-east-1.elasticmapreduce/libs/script-runner/script-runner.jar',
'Args': [
's3://my-bucket/spark-driver-install.sh',
]
}
},
...other steps...
]
Which, as you've experienced, will fail on EMR 4.x if you just swap command-runner.jar for script-runner.jar, there.
Instead, make a bootstrap action to call the script, like:
BootstrapActions=[
{
'Name': 'Install My Spark Drivers',
'ScriptBootstrapAction': {
'Path': 's3://my-bucket/spark-driver-install.sh',
'Args': []
}
}
]
The above example is expressed as boto3 run_job_flow kwargs. It's not immediately obvious to me how to accomplish the same thing in the web console, though.
For executing a script you can use script-runner. I was also facing the same issue. My script had ^M characters which was causing this issue. Removing those worked.

Executing Windows shell commands using 'not-installed' Java

I can't install Java on the computer, I only have a 'Java folder' on my desktop. Because of that executing 'cmd.exe' commands with Java doesn't work. Is there any method of pointing to the 'cmd.exe' and telling java to run a command using it?
I mean somethind similar to what I do in my 'start.bat' file i use to run .jar's - start C:\Users\kamilkime\Desktop\JEclipse\Java\jdk1.7.0_75\bin\java -jar Calculator.jar
I tried using this two methods, both don't work and throw the same exception:
//Method 1
Runtime.getRuntime().exec("cls");
//Method 2
ProcessBuilder builder = new ProcessBuilder("cls");
builder.start();
//Exception stacktrace
java.io.IOException: Cannot run program "cls": CreateProcess error=2, Nie można odnaleźć określonego pl
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1047)
at java.lang.Runtime.exec(Runtime.java:617)
at java.lang.Runtime.exec(Runtime.java:450)
at java.lang.Runtime.exec(Runtime.java:347)
at com.gmail.kamilkime.Main.clearConsole(Main.java:82)
at com.gmail.kamilkime.Main.start(Main.java:61)
at com.gmail.kamilkime.Main.main(Main.java:36)
Caused by: java.io.IOException: CreateProcess error=2, Nie można odnaleźć określonego pl
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:385)
at java.lang.ProcessImpl.start(ProcessImpl.java:136)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1028)
... 6 more
//edit 08.10.2015
Ok, so thanks to #9dan I've managed to run a console window, but... Now I can't do anything with it - cannot println() a message, cannot get a user input. Is it posibble to do sth like that (printing/getting input)?
BTW, the thing I'm trying to do the whole time is finding a way to enable the console program by double-clicking the .jar file, not by using 'java' command in 'cmd.exe'.
Now, I'm using this code and I'm stuck - I don't know what to do: http://pastebin.com/VLkr1RFd

Error under the following program to write R Script separately

Calling R in java-Rcaller
After following above link I've created new "myScript.R" seperately.
Please tell me that it is showing "save workspace" for saving. I've saved it as file with .R extension. Please correct me if I'm wrong.
I'm recieving the following error on running this as same Java program (provided in above link) created in Netbeans IDE for connecting RCaller with Java:
run:
java.io.IOException: Cannot run program "Rscript": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1042)
at java.lang.Runtime.exec(Runtime.java:615)
at java.lang.Runtime.exec(Runtime.java:448)
at java.lang.Runtime.exec(Runtime.java:345)
at javaapplicationrcaller2.JavaApplicationRCaller2.<init>(JavaApplicationRCaller2.java:41)
at javaapplicationrcaller2.JavaApplicationRCaller2.main(JavaApplicationRCaller2.java:25)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:288)
at java.lang.ProcessImpl.start(ProcessImpl.java:133)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1023)
... 5 more
BUILD SUCCESSFUL (total time: 0 seconds)

Exception in compiling code with JavaCPP?

I am trying to run there own example of LegacyLibrary on http://code.google.com/p/javacpp/
when I try to compile code with following command mentioned at site only (basically compiling code with javacpp.jar) I am getting following exception
D:\Java Workspace\POC\JavaCPP\bin>java -jar javacpp.jar LegacyLibrary
Generating source file: D:\Java Workspace\POC\JavaCPP\bin\jniLegacyLibrary.cpp
Building library file: D:\Java Workspace\POC\JavaCPP\bin\windows-x86\jniLegacyLibrary.dll
cl "/IC:\Program Files (x86)\Java\jdk1.6.0_03\include" "/IC:\Program Files (x86)\Java\jdk1.6.0_03\include\win32" "D:\Java Workspace\POC\JavaCPP\bin\jniLegacyLibrary.cpp" /W3 /Oi
/O2 /EHsc /Gy /GL /MD /LD /link "/OUT:D:\Java Workspace\POC\JavaCPP\bin\windows-x86\jniLegacyLibrary.dll"
Exception in thread "main" java.io.IOException: Cannot run program "cl": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:459)
at com.googlecode.javacpp.Builder.build(Builder.java:189)
at com.googlecode.javacpp.Builder.generateAndBuild(Builder.java:234)
at com.googlecode.javacpp.Builder.main(Builder.java:479)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:81)
at java.lang.ProcessImpl.start(ProcessImpl.java:30)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:452)
... 3 more
what the remedy for this ?
The error message is pretty clear: it's not finding the cl executable, which is the name of the Visual Studio compiler.
You should run that command from a Visual Studio command prompt (there's an entry in the start menu for that, usually), to get the right environment variables loaded.

How to clear console in java (Using netbeans)

I am using jdj 1.7,netbeans 7 versions. I wrote a program that's working fine. Now i want to clear the console window after many outputs in the console. I tried the below line Runtime.getRuntime().exec("cls"); also tried with exec("clear"). But i am getting these errors:
Exception in thread "main" java.io.IOException: Cannot run program "cls": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:459)
at java.lang.Runtime.exec(Runtime.java:593)
at java.lang.Runtime.exec(Runtime.java:431)
at java.lang.Runtime.exec(Runtime.java:328)
at Periodical.main(Book.java:88)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.(ProcessImpl.java:81)
at java.lang.ProcessImpl.start(ProcessImpl.java:30)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:452)
What's the problem here. How can i clear the console? Thank you
If you want to keep it portable you might want to use a library like jcurses. That will save you the trouble of having to detect what kind of console/terminal you are on and will give you a lot of other nice features like cursor and color control.

Categories