aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes run a bat in a new dos window Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "run a bat in a new dos window " Watch "run a bat in a new dos window " New topic
Author

run a bat in a new dos window

miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
i can write an ant task that runs a certain bat file; what i want is a way to have it running in a new (dos) window

how can i do it?

TiA


java amateur
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
What do you want to accomplish?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
my bat launches an hsqldb server instance; what i want is the ability to manually close the server if i wish so (by closing the dos window); as i have it now, even after closing the dos window server keeps alive
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
let me try to put it in another way:
when i run junit4 task (which depends on run bat file), it runs a bat file; since this results in getting a db server running, it stands alive, so the junit task itself never gets an oportunity to execute.
so, i'd like my task to launch the bat file in another dos window, so that my tests could get a chance to run
here's how it looks like:
C:\javaGranel\tag>ant junit4
Buildfile: build.xml

compilaRapido:

bat:

[exec] C:\javaGranel\tag>cd C:\javagranel\tag\data

[exec] C:\javaGranel\tag\data>java -classpath ../lib/hsqldb.jar org.hsqldb.Server
[exec] [Server@1a758cb]: [Thread[main,5,main]]: checkRunning(false) entered
[exec] [Server@1a758cb]: [Thread[main,5,main]]: checkRunning(false) exited
[exec] [Server@1a758cb]: Startup sequence initiated from main() method
[exec] [Server@1a758cb]: Loaded properties from [C:\javaGranel\tag\data\server.properties]
[exec] [Server@1a758cb]: Initiating startup sequence...
[exec] [Server@1a758cb]: Server socket opened successfully in 109 ms.
[exec] [Server@1a758cb]: Database [index=0, id=0, db=file:test, alias=] opened sucessfully
in 1141 ms.
[exec] [Server@1a758cb]: Startup sequence completed in 1250 ms.
[exec] [Server@1a758cb]: 2006-09-08 14:30:11.750 HSQLDB server 1.8.0 is online
[exec] [Server@1a758cb]: To close normally, connect and execute SHUTDOWN SQL
[exec] [Server@1a758cb]: From command line, use [Ctrl]+[C] to abort abruptly

and it stays there forever, so i've to manually keystroke control+C and finally answer y to y/n question, but, when i do it, the batch ends, and tests never run - and more - server isnt shut down

if i procceed, i get this time:
Pretende terminar a tarefa batch (S/N)? s

C:\javaGranel\tag>ant junit4
Buildfile: build.xml

compilaRapido:

bat:

[exec] C:\javaGranel\tag>cd C:\javagranel\tag\data

[exec] C:\javaGranel\tag\data>java -classpath ../lib/hsqldb.jar org.hsqldb.Server
[exec] [Server@1a758cb]: [Thread[main,5,main]]: checkRunning(false) entered
[exec] [Server@1a758cb]: [Thread[main,5,main]]: checkRunning(false) exited
[exec] [Server@1a758cb]: Startup sequence initiated from main() method
[exec] [Server@1a758cb]: Loaded properties from [C:\javaGranel\tag\data\server.properties]
[exec] [Server@1a758cb]: Initiating startup sequence...
[exec] [Server@1a758cb]: [Thread[HSQLDB Server @1a758cb,5,main]]: run()/openServerSocket():

[exec] java.net.BindException: Address already in use: JVM_Bind
[exec] [Server@1a758cb]: Initiating shutdown sequence...
[exec] at java.net.PlainSocketImpl.socketBind(Native Method)
[exec] [Server@1a758cb]: Shutdown sequence completed in 16 ms.
[exec] at java.net.PlainSocketImpl.bind(Unknown Source)
[exec] [Server@1a758cb]: 2006-09-08 14:32:30.328 SHUTDOWN : System.exit() is called next
[exec] at java.net.ServerSocket.bind(Unknown Source)
[exec] at java.net.ServerSocket.<init>(Unknown Source)
[exec] at java.net.ServerSocket.<init>(Unknown Source)
[exec] at org.hsqldb.HsqlSocketFactory.createServerSocket(Unknown Source)
[exec] at org.hsqldb.Server.openServerSocket(Unknown Source)
[exec] at org.hsqldb.Server.run(Unknown Source)
[exec] at org.hsqldb.Server.access$000(Unknown Source)
[exec] at org.hsqldb.Server$ServerThread.run(Unknown Source)

junit4:
[java] JUnit version 4.1
[java] .............................
[java] Time: 4,359

[java] OK (29 tests)


BUILD SUCCESSFUL
Total time: 8 seconds
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30929
    
158

Miguel,
Take a look at the spawn attribute of the exec task. Note that you will probably also want to use the waitFor task to allow the server to start up before running your integrationt tests.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
Originally posted by Jeanne Boyarsky:
Miguel,
Take a look at the spawn attribute of the exec task. Note that you will probably also want to use the waitFor task to allow the server to start up before running your integrationt tests.

Bingo!
i didnt feel the need of waitFor because first thing to happen in my task is precisely the server setup
thanks a lot, Jeanne!

PS please help me because when i try to post my build's relevant part i get a persistent error message stating i've to change '<' with &l t;, but even doing it i cant post

[ September 09, 2006: Message edited by: miguel lisboa ]
[ September 09, 2006: Message edited by: miguel lisboa ]
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30929
    
158

Originally posted by miguel lisboa:
PS please help me because when i try to post my build's relevant part i get a persistent error message stating i've to change '<' with &l t;, but even doing it i cant post

<target name="testingEscapeCharacters>

[edited to try alternatives for escape characters]
[ September 09, 2006: Message edited by: Jeanne Boyarsky ]
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30929
    
158

??? &lt; works for me.

You can try running your code through Eric's tool. Maybe you missed one <?
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
thanks again, Jeanne, but i've bad news: i hurried myself, so it doesnt perform like i intended to... i mean, server keeps running
i noticed ant has WLSTOP that stops a weblogic server, but that's all, i guess
now let me try your sugestion:
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
i came to an workable solution, though not quite elegant:
<target name = "junit4Incompleto" depends = "compilaRapido, bat">

<condition property = "SuiteClass" value = "${SuiteClass}">

<isset property = "SuiteClass" />

</condition>

<property name = "SuiteClass" value = "testes.TodosOsTestes" />

<java classname = "org.junit.runner.JUnitCore" fork = "yes" classpathref = "libraries">

<arg value = "${SuiteClass}" />

<classpath refid = "classpath" />

</java>

</target>



<target name = "junit4" depends = "junit4Incompleto">

<java classname = "persistencia.Hsql" fork = "yes" classpathref = "libraries">

<classpath refid = "classpath" />

</java>

</target>
and Hsql.java:
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30929
    
158

Thanks for sharing.
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
you'r welcome!
its a poor solution since whole proccess takes 8 seconds, while running tests takes only aprox. 3
 
 
subject: run a bat in a new dos window