Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble trying to execute application (java app) on remote server.

Status
Not open for further replies.

PPettit

IS-IT--Management
Sep 13, 2003
511
0
0
US
On a remote server, I've got a batch file that executes a Java app. Currently, I'm triggering the batch file with a scheduled task. I'd also like to be able to trigger the batch file or the Java app at will from a Windows app. Unfortunately, I can't seem to get it to work and I'm not entirely sure how to find out what's not working.

The java app is normally triggered by running a batch file(myapp_gt.bat) from a command prompt. The batch file simply contains this:
Code:
@echo off
.\jre6\bin\java -jar myapp.jar gt
When it runs, there's some mostly useless output to the command line. If there are files to download I think it ends with something like "X new files received". If nothing is downloaded, it ends with "No new files received"

I decided to bypass the batch file part and just remotely execute the Java app. I can see the Java process start and end on the server, but it seems like it ends too quickly and I don't see any evidence that the Java app did what it was supposed to do (i.e. download some XML files if they're present).

This is what I have so far:
Added reference to System.Management

Code:
CreateProcess("myserver", """c:\Program Files (x86)\myfolder\jre6\bin\java.exe"" -jar ""c:\Program Files (x86)\myfolder\myapp.jar"" gt", "mydomain\myusername>", "mypassword")

Code:
Private Sub CreateProcess(ByVal strComputer As String, ByVal strProcess As String, ByVal UserName As String, ByVal Password As String)
        Dim processBatch As ManagementClass = New ManagementClass("Win32_Process")
        Dim inParams As ManagementBaseObject = processBatch.GetMethodParameters("Create")
        Dim msc As ManagementScope

        inParams("CurrentDirectory") = Nothing
        inParams("CommandLine") = strProcess
        Dim co As ConnectionOptions = New ConnectionOptions()
        co.Username = UserName
        co.Password = Password

        Try
            If (strComputer = System.Environment.MachineName) Then
                msc = New Management.ManagementScope("\\" & strComputer & "\root\cimv2")
            Else
                msc = New Management.ManagementScope("\\" & strComputer & "\root\cimv2", co)
            End If

            msc.Connect()
            processBatch.Scope = msc
            Dim outParamas As ManagementBaseObject = Nothing
            outParamas = processBatch.InvokeMethod("Create", inParams, Nothing)
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

Can anyone tell me what I'm doing wrong, how to tell what's not working, or some alternate way to run the java app remotely (without using a third-party utility like PSExec). Also, I need some way to determine when this process has ended so that I can make sure that the rest of my code executes only after the Java app has finished.


 
I think I've found a solution for running the Java app. I still haven't worked out a way to detect the end of the process or capture the output, though. The main issue seems to be that I needed to set the current directory. Passing the full path for the Java executable and the full path for the .JAR file wasn't enough. I also went back to running the batch file since I could stick a command in there to redirect the output to a log file.

Code:
CreateProcess("myserver", [highlight #FCE94F]"c:\Program Files (x86)\myfolder\",[/highlight] """c:\Program Files (x86)\myfolder\myapp.bat""", "mydomain\myusername", "mypassword")

Code:
Private Sub CreateProcess(ByVal strComputer As String, [highlight #FCE94F]ByVal strCurrentDirectory As String,[/highlight] ByVal strProcess As String, ByVal UserName As String, ByVal Password As String)
        Dim processBatch As ManagementClass = New ManagementClass("Win32_Process")
        Dim inParams As ManagementBaseObject = processBatch.GetMethodParameters("Create")
        Dim msc As ManagementScope

        inParams("CurrentDirectory") = [highlight #FCE94F]strCurrentDirectory[/highlight]
        inParams("CommandLine") = strProcess
        Dim co As ConnectionOptions = New ConnectionOptions()
        co.Username = UserName
        co.Password = Password

        Try
            If (strComputer = System.Environment.MachineName) Then
                msc = New Management.ManagementScope("\\" & strComputer & "\root\cimv2")
            Else
                msc = New Management.ManagementScope("\\" & strComputer & "\root\cimv2", co)
            End If

            msc.Connect()
            processBatch.Scope = msc

            Dim outParams As ManagementBaseObject = Nothing
            outParams = processBatch.InvokeMethod("Create", inParams, Nothing)
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top