Starting a blank console - java

IS there any way to start a blank console in Windows platform ?
I'm writing a CLI where i want to open a separate window where user can log in and write their own command. When executing with cmd /c start command, it starts windows standard console.
Is there any other command ???

Assuming you're trying to start a java jar file, use a command like this:
start /d "%~dp0" java -jar "%~dp0\fpa.jar"
%~dp0 expands to the drive letter and path in which the batch file is located. Use that if you want to want to make sure that the PWD when running is the same location as the batch file. Otherwise, juse use
start java -jar "%~dp0\fpa.jar"
This will make sure that the batch file works even if you run it when not in the same directory as the jar file, as long as the jar file is in the same directory as the batch file.
You may need to make sure that java is in your path by having a line like
set path=jre6\bin;%PATH%
Also, you can eliminate the command line windows that comes up (for a GUI program by example) by using javaw instead of java.

You can use batch file in windows which would in turn start application that would accept user input. Something similar to this :
start cmd /c myapp.bat

Related

Windows batch file : How to redirect console logs of a background process to 'NUL'

I have created a batch file which calls a java process in background. All I want is to redirect the logs of the java process to a 'NUL' output so that the background terminal does not contain any output.
Contents of my batch file:
#echo off
START /MIN java -jar ./myapp.jar >null 2>&1
However when I run the batch, I minimized windows terminal opens up which still displays all the logs.
I require to disable this logging, without changing the app.jar
If you just want to ignore any console input and output, execute your Java program on a Windows platform and need to prevent the opening of a console window, then use the javaw executable instead of java.
dotvav's solution is best in your scenario, but for the record the proximate problem with your batch script as posted is that the redirection applies to the START command, not to the java command.
A corrected version would look something like this:
START /MIN cmd /c "java -jar ./myapp.jar >NUL 2>&1"

creating a bat file which sends to background and closes (1 file)

im trying to do something simple, i want to start Burp Suite with extra java memory, but i don't want the CMD window to stay open.
If i don't use a .bat file and simple open cmd and type start /b "" java -jar -Xmx2g burpsuite_pro_v1.6.07.jar, Burp opens, the the process is sent to background, but the CMD window stays open. i can, however, close it manually and Burp will keep working.
when i try to put the thing into a CMD window, it will not even be sent to background, Burp stays dependent on the CMD, and i cant even add exit to the file.
i tried to solve the issue by following:
run bat file in background - this worked, but required me to have THREE files, i prefer a more elegant "1 file solution"
Just add the below line in your bat file and the java procees will run in background with no window open!
start javaw {Path of Your jar or Java file}
The following batch file commands should accomplish your purpose:
start "" /B java.exe -Xmx2g -jar burpsuite_pro_v1.6.07.jar
exit
You can probably even leave out the /B switch.
References
How can I run a program from a batch file without leaving the console open after the program start?
How to use the start command in a batch file?
Turns out the solution was simple: using javaw.
the issue was with using java.exe, some attempts even closed the CMD but opened a java.exe window (blank)
modding the file to contain:
start javaw -Xmx2g -jar burpsuite_pro_v1.6.07.jar solved it for me.

launching java program via batch and php,

php and batch files.
So i'm executing batch files through php
I have no issues launching the batch.
$str = exec('C:\WINDOWS\system32\cmd.exe /c START C:\MInecraft\_restart.bat');
However the issue im having is getting the batch file to work currectly. When the batch is run, it executes this code
taskkill /IM java.exe /F
java -Xmx1024M -jar craftbukkit.jar -o true
batch file successfully runs the taskkill command when launched with php, however it will not run the next line. When ran manually it launches fine, (bear in mind that the cmd.exe does not exit it stays open with this code)
Any ideas on how i can get this to launch from php?
Maybe the reason is the same as given at Error Executing Batch file of BlazeDS, the java executable is not found by Windows on running the batch file from within PHP script.
The current working directory or the directories listed in environment variable PATH can be different when the batch file is executed from within the PHP script in comparison to running the batch file manually.
Do you have ever tried to specify java.exe with full path in double quotes in the batch file?
You could also add at top of the batch file the commands
dir /w
PATH
to see which directory is the current directory and which directories are listed in environment variable PATH on execution of the batch file from within PHP script.
Forgot to post back here, I specified java through windows path command rather than the batch. The problem is because the java process takes the cmd and turns it into a console, it never finishes the batch file. So, the php never returns and continues the code unless the batch is force ably closed on the server.
pclose(popen("start /B C:\MInecraft\_restart.bat &", "r")); die();
I ended up using this command, which i believe makes it launch the batch and not wait for a reply. Just carry on with the php.
Thanks for your kind reply. I did initially try launching java in multiple ways.

How to call for the system console in Java?

I made a console-based Java application but every time I try to start the .jar file by clicking on it the program seems to be running but there is no console displayed. Is there specific code I must write in order to call for the system console?
Can you start the console first , change directory to where your jar file is and then run java -jar yiurjarfilename ?
The OS takes care of displaying console output. There is no code that you can write within Java to display or hide the "console" (because within Java, there's only standard output & error streams that you write to).
Windows usually leaves the console open after your program exits, but there might be a setting within the Java Runtime Environment that configures that behavior.
gcivil is right, you can see the results in console only if you start from console, if you are in windows you can open the command line Super + R and type cmd, then press enter (Super is the one with the Windows icon)
there you can type : java -jar "absolute path to your file" (don't forget the quotes)
another way is create a .bat file next to the .jar one, the bat file should contain
java -jar filename.jar
you don't need the quotes nor absolute path since it is next to the .bat file now you can double click that instead of the .jar
Once the app is terminated it will close the console, if you need to see what is next you have to add pause
java -jar filename.jar
pause

Executable Jar not Displaying Output

I have an executable jar that I know is executing, because I put two distinct beeps at the beginning of the code that I hear whenever I double click on it or when I run it through the cli. Even when I run it through the command line however, it does not display output nor prompt for input when I use System.out/System.in respectively. Everything is functional when I run it through eclipse.
How do I get the .jar to output/input to the same command line I executed it in?
Assuming java is in your PATH, you should lauch your program as follows :
java -jar myProgram.jar
If you want to run it without opening the command line, you could create a .cmd file in the same directory with this content :
#echo off
java -jar myProgram.jar
pause
then, double-click on the .cmd file.

Categories

Resources