> > I have some batch files stored in a jar file. Can I execute them while
> > they are in the jar file or do I need to get them out first and put them
[quoted text clipped - 8 lines]
>
> Arne

Signature
Sabine Dinis Blochberger
Op3racional
www.op3racional.eu
> Arne Vajhřj wrote:
>>> I have some batch files stored in a jar file. Can I execute them while
[quoted text clipped - 8 lines]
>
> I wonder if you could pipe it in? Just a curiousity.
You mean:
program-that-read-from-jar-and-write-to-stdout | cmd
?
Interesting idea.
I don't know if it will work.
Arne
Gordon Beaton - 12 Nov 2007 14:27 GMT
>> I wonder if you could pipe it in? Just a curiousity.
>
[quoted text clipped - 7 lines]
>
> I don't know if it will work.
While the pipe example may just work, realize that in this case cmd
isn't executing a batch file per se, it's executing a sequence of
commands entered as though they were entered individually at the
command line.
IIRC batch files can contain some things that work differently (or
perhaps not at all) when entered on the command line, although I admit
that things may have changed in the 15 or so years since I've used MS
DOS. Testing the value of environment variables comes to mind.
The suggestion would however likely work with any Unix shell, which
doesn't typically make this kind of distinction.
/gordon
--
zfkmk@yahoo.com - 12 Nov 2007 19:20 GMT
On Nov 12, 7:59 am, Arne Vajh?j <a...@vajhoej.dk> wrote:
> > Arne Vajh j wrote:
> >>> I have some batch files stored in a jar file. Can I execute them while
[quoted text clipped - 20 lines]
>
> Arne
Why not? Well, depending on what the OP wants, there may be issues, of
course. I just tried the following quick and dirty test and it seems
to work:
import java.io.*;
import java.util.*;
import static java.lang.System.out;
public class Bat {
public static void main (String[] args) throws Exception {
String bat =
"echo Hello\n" +
"set java=%SystemRoot%\\system32\\java.exe\n" +
"set | find \"java\"\n" +
"dir %java%\n";
Runtime rt = Runtime.getRuntime ();
Process process = rt.exec ("cmd");
InputStream stderr = process.getErrorStream ();
InputStream stdout = process.getInputStream ();
OutputStream stdin = process.getOutputStream ();
stdin.write (bat.getBytes ());
stdin.close ();
BufferedReader br;
String line;
br = new BufferedReader (new InputStreamReader (stdout));
while ((line = br.readLine ()) != null)
out.println ("stdout=" + line);
br = new BufferedReader (new InputStreamReader (stderr));
while ((line = br.readLine ()) != null)
out.println ("stderr=" + line);
}
}
Eugene
Arne Vajhøj - 13 Nov 2007 02:43 GMT
>> You mean:
>>
[quoted text clipped - 38 lines]
> }
> }
Yep.
But try with:
String bat =
"@echo off\n" +
"goto bot\n" +
":top\n" +
"echo top\n" +
"goto fin\n" +
":bot\n" +
"echo bot\n" +
"goto top\n" +
":fin\n";
Arne
Eugene Zharkov - 13 Nov 2007 03:16 GMT
On Nov 12, 8:43 pm, Arne Vajh?j <a...@vajhoej.dk> wrote:
> zf...@yahoo.com wrote:
> > On Nov 12, 7:59 am, Arne Vajh?j <a...@vajhoej.dk> wrote:
[quoted text clipped - 57 lines]
>
> Arne
Oh well. I guess it is not that simple, after all.
Eugene