running command line commands with arguments...

D

doneirik

Dear forum,

I need to run a command line like command with arguments in the java
code.
Now I have things stored in a .bat file that I execute , however, I
would like to run everything from the java code itself. Would that be
possible?

java code:
Runtime r = Runtime.getRuntime();
try
{
String s = "latTest.bat";
r.exec(s);
}
catch (Exception ioe)
{}

bat file:

@ECHO OFF

cd c:\Program files\MikTex 2.5
pdflatex C:\Temp\testfile.tex
testfile.pdf
 
G

Gordon Beaton

I need to run a command line like command with arguments in the java
code. Now I have things stored in a .bat file that I execute ,
however, I would like to run everything from the java code itself.
Would that be possible?

Yes. Have you not read the API documentation for Runtime.exec()?

String cmd = "pdflatex C:\\Temp\\testfile.tex testfile.pdf"
File dir = new File("C:\\Program files\MikTex 2.5");
Process p = Runtime.getRuntime().exec(cmd, null, dir);

/gordon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top