Reading python script cmd output when executed by another .exe from cmd - java

I have written a Java project that uses Runtime.getRuntime.exec() to launch a .exe which then launches a python script.
Within the py script are several 'print(..)' commands that I wish to be read by java using getInputStream(). However, as the script is being launched by another .exe, 'print()' or sys.stdout.write() outputs do not appear in the cmd window. Is there a way to ensure all outputs return to cmd, or is there another way round it?
Thanks in advance!

Related

Can you run a Java jar file without going through the command line?

Made a game in Java and it is played using the console and the only way to run it is through the command line. Is there a way to run it without having to go through the process of going through the command line?
Batch Files (Win), Launch4J (Win), Shell Script (Unix/Linux/OS X)
You could just create a command line script depending on your OS which will start the game. Then you can create a shortcut and add an icon, so It will look like a common app.

Open gnome-terminal in background from Java

I'm trying to open gnome-terminal to execute a command from Java by the following code:
Runtime.getRuntime().exec(new String[]{"gnome-terminal", "-e", "command"});
But this code will show terminal for user, how I can open gnome-terminal in background?
You don't need to open a terminal visually to execute a command. Shell interpreter is a program which you can invoke without the terminal window. What terminal window does is it just sends what you type on the terminal, interacts with the underlying shell interpreter and gives you the results. When you need to run a OS specific command you would want to directly call the shell interpreter you want to with(i.e bash, csh, ksh) and get the result from within the Java program.
Working with commands and reading output from them is not that easy sometimes. So I would suggest you to have a look at Apache Exec which will ease reading data from externally invoked program.

not able to Execute shell script containing executable through android app

I have designed one android application in which i want to invoke shell script which in turn executes one executable(i have place both(script and executable) of them in assets folder).
My executable takes one argument as hex number
when i executes shell script through adb shell from my linux(ubuntu) manually, it is working fine but when application does try to execute that executable through script it is not working(not giving even error message).
here is script part;
/data/data/com.example.test/program 0x950000
Thanks in advance.

Java - System.out.println() viewable from application?

I have a Java application that runs great :) While uploading files, it uses the standard output to show progress : "System.out.println(...);".
When I run it in Eclipse, well it works perfectly, but when I run the JAR file, I don't see any console/terminal showing up and printing what I print through "System.out.println(...),".
How can I open a new terminal when my application is launched (it is a Swing application)?
Basically I want to be able to run the Swing application and show information on the side in a terminal / console. Why? Don't worry about why I want to do this ;)
Thanks a lot!
Regards.
Open terminal and run application as java -cp yourjar.jar YouMain or java -jar yourjar.jar if you jar is runnable.
I believe that you do not see output because you are running your application using javaw - the special windows-only variation of JVM that does not have STDOUT at all. If you want to click your application and see output map *.jar file to be opened using java instead of javaw. Alternatively write bat file that runs your application. In this case you will see console.
Use java instead of javaw to launch your application. Double-clicking on a jar executes it with javaw. Instead, open a command line window and type
java -jar thePathOfTheJarFile.jar
If you want to have something double-clickable, then write a shell script containing this command, and double-click the shell script instead of the jar.

Run Java file Service Mac

So far i've created a service using automator to compile a Java file. This means that i can compile a java file through its contextual menu.
Unfortunately I cannot do the same with running the Java file. Through automator I can get it to run the java file perfectly, showing the results in the automator window, however it will not open the Terminal window to view the java file. I did this using this code:
java -classpath `dirname "$1"` `basename "$1" | sed "s/.class//g"`
Applescript on the other hand can run Terminal commands into a Terminal window for all to see using code such as:
on run {input, parameters}
tell application "Terminal"
activate
do script with command "java -classpath" & input & input
end tell
end run
The correct way to run a java file is:
java -classpath /path/to/ file
Can anybody please help?
Thanks in advance.
Utilities > Run Shell Script with Passing input: as arguments seems to work in this context.
Addendum: If you want to open Terminal, something like this may work.
open -a Terminal ~/your/script.sh

Categories

Resources