B4J Question Inline java use vairable

Discussion in 'B4J Questions' started by Shivito1, Dec 29, 2017.

  1. Shivito1

    Shivito1 Active Member Licensed User

    Code:
    Code:
    #if java

        public static void foo() {
            try {
            @SuppressWarnings("unused")
            String command = "c:\\windows\\system32\\net.exe use f: " + x ;
    Process p = Runtime.getRuntime().exec(command);
    System.out.print("does not = 1");
            } catch (Exception name) {
                System.out.print("does not = 1");
    }}
            
    #End If
    Error:
    Code:
    src\b4j\example\main.java:216: error: cannot find symbol
            
    String command = "c:\\windows\\system32\\net.exe use f: " + x ;
                                                                        ^
      symbol:   variable x
      
    location: class main
    the Dim x as String is in the Process_Globals. Why cant I use it in the #If Java????
     
  2. Daestrum

    Daestrum Well-Known Member Licensed User

    Put a '_' before the variable name
    ie,
    Code:
    String command = "c:\\windows\\system32\\net.exe use f: " + _x ;
    All variables in Process_Globals in the output java code have a preceding underscore and are always lowercase even if defined with an uppercase name.
     
    jinyistudio, DonManfred and Shivito1 like this.
  3. Shivito1

    Shivito1 Active Member Licensed User

  4. Erel

    Erel Administrator Staff Member Licensed User

    Why aren't you using jShell library?

    Your code is wrong and could cause the app to freeze if the output of net.exe will be long.
     
    Shivito1 likes this.
  5. Shivito1

    Shivito1 Active Member Licensed User

    How would I use jShell to do the above? I could not quite figure it out. Sorry this is my first time using b4j.
    when I Googled my issue I found a java solution. That is why I did it the way I did.
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    Code:
    Dim shl As Shell
       shl.Initialize(
    "shl""c:\windows\system32\net.exe",  Array("use""f:", x))
       shl.Run(
    10000)
       
    Wait For shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
     
    If Success AND ExitCode = 0 Then
         
    Log("Success")
         
    Log(StdOut)
       
    Else
         
    Log("Error: " & StdErr)
       
    End If
    ]
     
    Shivito1 likes this.
  7. Shivito1

    Shivito1 Active Member Licensed User

    I see. Thanks Erel
     
Loading...
  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