Solved

Batch File not executing

Posted on 2013-06-14
19
595 Views
Last Modified: 2013-06-23
In my code below is what I have in my batch file right now.

However...
When I dbl click to start it the batchfile opens and closes right away.

If I open a command prompt and do the CD
Then paste in the java command and hit enter

The process runs...which opens a connection to our phone system and retrieves a continuous stream of data.

How do I get the batch file to run that way?

@echo off
cd "c:\program files (x86)\Java\jre7\bin"
java -cp m5.jar;m5-data-objects.jar;webservices-rt.jar;log4j-1.2.13.jar org.m5.sdk.hostedconnect.v2.MonitorMultipleExample > C:\temp\Output9999.txt

Open in new window

0
Comment
Question by:lrbrister
  • 5
  • 5
  • 5
  • +3
19 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 39247351
Start by running the batch file from the command line. Please report results
0
 
LVL 1

Expert Comment

by:djoray
ID: 39247353
I have two suggestions:
1.  If you are running this bat file from a drive other than C:, you will need to switch to that drive before running the CD command.

@echo off
c:
cd ...

2.  Use the pause command as the last line of the bat file.  This will prevent the window from closing immediately and allow you to see what the results of the command are.  This should allow you to do some troubleshooting based on what you find.
0
 
LVL 11

Expert Comment

by:Pradeep Dubey
ID: 39247357
run below and see whats happening in the cmd prompt.
@echo off
cd "c:\program files (x86)\Java\jre7\bin"
java -cp m5.jar;m5-data-objects.jar;webservices-rt.jar;log4j-1.2.13.jar org.m5.sdk.hostedconnect.v2.MonitorMultipleExample > C:\temp\Output9999.txt
pause

Make sure you are logged in as administrator or you have administrator rights.
0
 

Author Comment

by:lrbrister
ID: 39247392
Hey guys...
Tried all your suggestions
The second line is not executing...that java

But if I open the command prompt...and run one after another they all work
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 39247406
Use /d on the CD line to move to that directory if needed, as has been suggested above the working directory is probably not on the C: drive for your shortuct.

@echo off
cd /d "c:\program files (x86)\Java\jre7\bin"
java -cp m5.jar;m5-data-objects.jar;webservices-rt.jar;log4j-1.2.13.jar org.m5.sdk.hostedconnect.v2.MonitorMultipleExample > C:\temp\Output9999.txt
                                  

Open in new window


Start a cmd.exe prompt, then run your batch file, does that work, and/or remove the redirect (> and the filename after it) and add another line PAUSE after the Java command so that you can see any errors:

@echo off
cd /d "c:\program files (x86)\Java\jre7\bin"
java -cp m5.jar;m5-data-objects.jar;webservices-rt.jar;log4j-1.2.13.jar org.m5.sdk.hostedconnect.v2.MonitorMultipleExample
pause

Open in new window

0
 
LVL 11

Expert Comment

by:Pradeep Dubey
ID: 39247413
2nd line is
java -cp m5.jar;m5-data-objects.jar;webservices-rt.jar;log4j-1.2.13.jar org.m5.sdk.hostedconnect.v2.MonitorMultipleExample > C:\temp\Output9999.txt

Can you provide screenshot of your batch file.
0
 

Author Comment

by:lrbrister
ID: 39247452
In all of the suggestions above...
The directory is changed
But the java line is simply not executing

screenshot of batch file is attached

with vb code I can run with this...where the commandString is the same as above...

The numbers added are to monitor specific phones instead of all
The commandString variable is what you see on the Java line above.
' Specify the location of the binary
        p.FileName = "cmd.exe"
        p.WorkingDirectory = "C:\Program Files (x86)\Java\jre7\bin\"

        ' Use these arguments for the process
        p.Arguments = commandString & " 9176150266 9176150267 9176150268 > C:\temp\Output3.txt"

        ' Use a hidden window
        p.WindowStyle = ProcessWindowStyle.Hidden

        ' Start the process
        Process.Start(p)

        Dim intResponse As Integer
        intResponse = MsgBox("End?", vbYesNoCancel, "Alert")
        If intResponse = vbYes Then
            For Each java In Process.GetProcessesByName("Java")
                Try
                    java.Kill()
                Catch
                End Try
            Next[embed=file 660092]

Open in new window

Capture.PNG
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 39247471
Ok, remove the cmd /k and try again
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 39247479
i.e. as in http:#a39247406 .

The cmd.exe /k will be launching a new command prompt process and telling to stay resident, and run the cd command in there... so yes it will never make it to the next line of the batch file, it probably would if you typed "exit" then instead of pressin the "x" button to close it.

Steve
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 86

Expert Comment

by:CEHJ
ID: 39247480
Actually your batch file is already 'wrong' as those jars should not be in the Java bin directory
You should place them elsewhere and then use the -classpath to execute the correct classes, setting PATH temporarily (if necessary)
0
 
LVL 51

Expert Comment

by:Bill Prew
ID: 39247539
Add a PAUSE to the end of the BAT, remove the output redirection, and let us know what is displayed.

@echo off
cd /d "c:\program files (x86)\Java\jre7\bin"
java -cp m5.jar;m5-data-objects.jar;webservices-rt.jar;log4j-1.2.13.jar org.m5.sdk.hostedconnect.v2.MonitorMultipleExample
pause

Open in new window

~bp
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 39247571
those jars should not be in the Java bin directory
In fact, they WILL be deleted from there on the next update of the JRE, since the default action of the JRE updater is to remove the (usually insecure) previous one

Your batch file should look more like

@echo off
:: Better to set JAVA_HOME as env car
SET JAVA_HOME="c:\program files (x86)\Java\jre7"
SET PATH="%JAVA_HOME\bin;%PATH%"
SET LIB_DIR="%USERPROFILE%\foo"
cd /d "%LIB_DIR%"
:: (All jars in LIB_DIR)
java -cp m5.jar;m5-data-objects.jar;webservices-rt.jar;log4j-1.2.13.jar org.m5.sdk.hostedconnect.v2.MonitorMultipleExample > C:\temp\Output9999.txt

Open in new window

0
 

Author Comment

by:lrbrister
ID: 39247999
CEHJ

Thanks. I know that.
This is only on my dev pc and I'm making sure it works before I set to a production server
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39249069
Yes, but do it right wherever you do it ;)
0
 

Author Closing Comment

by:lrbrister
ID: 39256090
I applied your answer in Visual Basic processes and it worked.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39256143
:)
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 39256513
As a matter of interest did it work when you just removed the "cmd /k" that shouldn't have been there before you shuffled the jar files into a neater structure?
0
 

Author Comment

by:lrbrister
ID: 39256538
dragon-it
I tried that...in fact I tried every suggestion.

For some reason I could not get that thing to work.

I was about to go postal (LOL) so went with other apprach.

I've probably done hundreds of batch file in my time...this one just wouldn't work.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 39256567
No problem, just wanted to know for myself, you've got a better solution there now anyway,

Steve
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
network copying issue 4 40
JList custom Cell Renderer refresh 15 43
Java Timer (static) 9 19
Birthdays 3 21
This article will show, step by step, how to integrate R code into a R Sweave document
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now