Spanish Problema al ejecutar un comando en consola de linux(raspberry)

lukaz612

New Member
Hola, estoy desarrollando una interfaz para comunicarme desde un celular a una raspberry mediante wifi, hasta ahora me descargue los ejemplos de simplechat, el problema es que quiero ejecutar un comando en la consola de linux, en realidad si se ejecuta (video) pero ya luego el programa de b4j se cierra, ya he hecho por separado ejecutar aplicaciones con la consola, sin embargo aquí me genera el siguiente error al finalizar el vídeo.

Connected: true
main._appstart (java line: 70)
java.lang.RuntimeException: java.lang.NullPointerException
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:120)
at anywheresoftware.b4a.BA$3.run(BA.java:247)
at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:30)
at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:26)
at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:153)
at b4j.example.main._appstart(main.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
at b4j.example.main.main(main.java:30)
Caused by: java.lang.NullPointerException
at anywheresoftware.b4j.object.WebSocket.access$0(WebSocket.java:134)
at anywheresoftware.b4j.object.WebSocket$JQueryElement.RunMethod(WebSocket.java:195)
at anywheresoftware.b4j.object.WebSocket$JQueryElement.SetText(WebSocket.java:246)
at b4j.example.main$ResumableSub_NewMessage.resume(main.java:120)
at b4j.example.main._newmessage(main.java:76)
at b4j.example.connector._client_messagearrived(connector.java:83)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
... 12 more
Gracias (no encontre la manera de como subir los .zip de mi trabajo para informacion) les dejo mi codigo en java
B4X:
'Non-UI application (console / server application)
#Region Project Attributes
    #CommandLineArgs:
    #MergeLibraries: True
#End Region

#If JAVA
import java.io.BufferedReader;
import java.io.InputStreamReader;

//Execute a command AND capture the output In a String
//Parameter: Command To run
//Returns: String with the command output
public static String ExecuteCommand(String command) {
 
    StringBuffer output = new StringBuffer();
 
    Process p;
    try
    {
        p = Runtime.getRuntime().exec(command);
        p.waitFor();
        BufferedReader reader =
            new BufferedReader(new InputStreamReader(p.getInputStream()));
             String line = "";           
            while ((line = reader.readLine())!= null)
            {
                output.append(line + "\n");
            }
 
    }
    catch (Exception e)
    {
        //e.printStackTrace();
        return "Error executing command " + command;
    }
 
    //System.out.println(output);
    return output.toString();
}

#End If
Sub Process_Globals
    'Private fx As JFX
    'Public MainForm As Form
'    Private btnConnect As Button
    'Private btnSend As Button
'    Private Label1 As Label
    'Private lstUsers As ListView
'    Private txtHost As TextField
'    Private txtLogs As TextArea
    'Private txtMessage As TextField
    Type Message (Body As String, From As String)
'    Private txtName As TextField
    Private DirData As String
'    Private palabra As String
    Public joInlineJava As JavaObject = Me
    Private consoleoutput As JQueryElement

End Sub

Sub AppStart (Args() As String)
    DirData=File.DirData("controladorjava")
    Connector.ConnectTo("192.168.1.64", "ServidorJava")
    StartMessageLoop
End Sub

'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

Public Sub NewMessage(msg As Message)
    'txtLogs.Text = txtLogs.Text & $"${msg.From}: ${msg.Body}"$ & CRLF
    'txtLogs.SetSelection(txtLogs.Text.Length, txtLogs.Text.Length)
    
    If msg.Body = "1" Then
    
        Dim cmd As String
        cmd = "omxplayer /home/pi/Desktop/pregunta1.mp4"
        Dim Res As String = joInlineJava.RunMethod("ExecuteCommand",Array(cmd))
        consoleoutput.SetText(Res)
    '    Dim palabra As String = "a" sirve para enviar la pabra o el estrig que se desea
    '    Connector.SendMessage(palabra) enviar palabra   
    Sleep(5000)
        StopMessageLoop
    End If
    
    If msg.Body = "2" Then
        Dim cmd As String
        cmd = "omxplayer /home/pi/Desktop/pregunta2.mp4"
        Dim Res As String = joInlineJava.RunMethod("ExecuteCommand",Array(cmd))
        consoleoutput.SetText(Res)
    End If
    
    If msg.Body = "3" Then
        'Dim cmd As String
        'cmd = "omxplayer /home/pi/Desktop/pregunta3.avi"
        'Dim Res As String = joInlineJava.RunMethod("ExecuteCommand",Array(cmd))
        'consoleoutput.SetText(Res)
        
        Dim shl As Shell
        Dim cmd As String = "omxplayer /home/pi/Desktop/pregunta3.avi"
        shl.Initialize("shl","omxplayer /home/pi/Desktop/pregunta3.avi",Array(cmd))
        shl.Run(10000)
    End If
End Sub

Sub txtMessage_Action
    'btnSend_Action
End Sub

Public Sub NewUsers(Users As List)
    'stUsers.Items.Clear
    'For Each u As String In Users
    '    lstUsers.Items.Add(u)
'    Next
End Sub
//segundoo
B4X:
Sub Process_Globals
    Private client As MqttClient
    Private const port As Int = 51042
    Private serializator As B4XSerializator
    Public connected As Boolean
    Private currentName As String
    
End Sub


Public Sub ConnectTo(Host As String, Name As String)
    Disconnect
    currentName = Name
    client.Initialize("client", $"tcp://${Host}:${port}"$, "desktop" & Rnd(1, 10000000))
    Dim mo As MqttConnectOptions
    mo.Initialize("", "")
    mo.SetLastWill("all/disconnect", serializator.ConvertObjectToBytes(currentName), 0, False)
    client.Connect2(mo)
End Sub

Private Sub client_Connected (Success As Boolean)
    Log($"Connected: ${Success}"$)
    If Success Then
        connected = True
        client.Subscribe("all/#", 0)
        client.Publish2("all/connect", serializator.ConvertObjectToBytes(currentName), 0, False)
    Else
    '    fx.Msgbox(Main.MainForm, "Error connecting: " & LastException, "")
    End If
End Sub

Private Sub client_MessageArrived (Topic As String, Payload() As Byte)
    Dim receivedObject As Object = serializator.ConvertBytesToObject(Payload)
    If Topic = "all/connect" Or Topic = "all/disconnect" Then
        'new client has connected or disconnected
        'do nothing. The server will handle it.
    Else if Topic = "all/users" Then
        Dim newUsers As List = receivedObject
        Main.NewUsers(newUsers)
    Else
        Dim m As Message = receivedObject
        Main.NewMessage(m)
    End If
        
End Sub

Public Sub SendMessage(Body As String)
    If connected Then
        client.Publish2("all", CreateMessage(Body), 0, False)
    End If
End Sub

Public Sub Disconnect
    If connected Then
        connected = False
        client.Publish2("all/disconnect", serializator.ConvertObjectToBytes(currentName), 0, False)
        client.Close
    End If
End Sub

Private Sub CreateMessage(Body As String) As Byte()
    Dim m As Message
    m.Initialize
    m.Body = Body
    m.From = currentName
    Return serializator.ConvertObjectToBytes(m)
End Sub

Private Sub client_Disconnected
    If connected Then
    End If
    connected = False
End Sub


Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

Sub Service_Destroy

End Sub
 

josejad

Expert
Licensed User
Longtime User
Cookies are required to use this site. You must accept them to continue using the site. Learn more…