Batch File not executing

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

Larry Bristersr. DeveloperAsked:
Who is Participating?
 
CEHJConnect With a Mentor Commented:
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
 
CEHJCommented:
Start by running the batch file from the command line. Please report results
0
 
djorayCommented:
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
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
Pradeep DubeyConsultantCommented:
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
 
Larry Bristersr. DeveloperAuthor Commented:
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
 
Steve KnightIT ConsultancyCommented:
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
 
Pradeep DubeyConsultantCommented:
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
 
Larry Bristersr. DeveloperAuthor Commented:
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
 
Steve KnightIT ConsultancyCommented:
Ok, remove the cmd /k and try again
0
 
Steve KnightIT ConsultancyCommented:
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
 
CEHJCommented:
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
 
Bill PrewCommented:
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
 
Larry Bristersr. DeveloperAuthor Commented:
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
 
CEHJCommented:
Yes, but do it right wherever you do it ;)
0
 
Larry Bristersr. DeveloperAuthor Commented:
I applied your answer in Visual Basic processes and it worked.
0
 
CEHJCommented:
:)
0
 
Steve KnightIT ConsultancyCommented:
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
 
Larry Bristersr. DeveloperAuthor Commented:
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
 
Steve KnightIT ConsultancyCommented:
No problem, just wanted to know for myself, you've got a better solution there now anyway,

Steve
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.