B4J Question issue with linux and Jshell

codie01

Active Member
Licensed User
Longtime User
Hi guys,

I have a bash script that stops and starts a service. Script as follows:

bash script:
#! /bin/bash

if [ "$1" == "start" ]; then
   sudo systemctl start bgwSales.service
   echo "bgwSales started"
fi

if [ "$1" == "stop" ]; then
   sudo systemctl stop bgwSales.service
   echo "bgwSales.service stopped"
fi

From putty (terminal) typing sh bgwSales.sh start and stop it works correctly.

I then have a b4j app that reads service(s) status from a table. If the service has not update last run time and this time has expired. I run a jshell routine as follows:

Monitor time and if expired run jshell:
                Log("starting bgwSales service")
                Dim clickedApp As String = "bgwSales.sh"
                Dim clickedCommand As String = "start"
                Run_Command(File.DirApp&"/"& clickedApp, Array As String(clickedCommand))

And the run command code is as follows:

run jshell command:
Sub Run_Command( cli As String, args As List)
    Try
        Log( "Run_Command")
        Dim sh As Shell
        sh.Initialize("cli",cli,args)
        'sh.InitializeDoNotHandleQuotes("cli", cli, args)
        sh.Run(-1)    '<<< changed
      
        Wait for cli_ProcessCompleted( Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
        
        If Success Then
            Log(Success & "; ExitCode = " & ExitCode)
            Log("StdOut = " &  StdOut)
            Log("StdErr = " &  StdErr)
        Else
            Log(Success & "; ExitCode = " & ExitCode)
            Log("StdOut = " &  StdOut)
            Log("StdErr = " &  StdErr)
        End If
        Catch
        Log("RUN:COMMAND : " & cli & " Failed!")
    End Try
End Sub

The issue I have is if I pass "stop" it works perfectly,

If I pass "start" it does not work at all. StdOut returned is "", success is true

I have a theory to start a service I need to pass a superuser and and password. maybe. does anyone know how to pass these.

Thanks
 

teddybear

Well-Known Member
Licensed User
If you passed start, what are StdErr and Exitcode you got
 
Upvote 0
Top