B4J Question Raspberry CMDs

Discussion in 'B4J Questions' started by luke2012, Jul 2, 2015.

  1. luke2012

    luke2012 Well-Known Member Licensed User

    Hi to all,
    how to call linux commands (rasbian) within a web app ?
  2. rwblinn

    rwblinn Well-Known Member Licensed User


    various ways, like jShell or InLine Java.
    Look here for an open source example using InLine Java to run commands. Check the files rpiconsole.b4j and rpiconsole.bas.

    #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
    //Dim cmd as String = "ls"
    //Dim result As String = Main.joInlineJava.RunMethod("ExecuteCommand", Array(cmd))

    public static String ExecuteCommand(String command) {
        StringBuffer output = new StringBuffer();
        Process p;
            p = Runtime.getRuntime().exec(command);
            BufferedReader reader =
                new BufferedReader(new InputStreamReader(p.getInputStream()));
                 String line = "";           
                while ((line = reader.readLine())!= null)
                    output.append(line + "\n");
        catch (Exception e)
            return "Error executing command " + command;
        return output.toString();

    #End If
    Daniel Uribe and luke2012 like this.
  3. luke2012

    luke2012 Well-Known Member Licensed User

    Great Work and thanks for your reply!
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice