B4J Question Help with SHELL

Discussion in 'B4J Questions' started by Num3, May 12, 2018.

  1. Num3

    Num3 Member Licensed User

    Hi all,

    First post :)

    I am trying to execute the following code (which works with other programming languages PHP, C etc), but i cannot get a return in B4J, help is appreciated!
    Code:
    Dim s_input As String ="2008-03-10;2008-03-10T15:58:00;FT 1/1;28.07;"
       
    'Dim s_query As String = "/c echo.|set/p=" +Chr(34) + s_input + Chr(34) + " | openssl dgst -sha1 -sign chave_privada.txt | openssl enc -A -base64"

       
    'params.Add("/c echo. | set /p=" & Chr(34) & s_input & Chr(34) &" | openssl dgst -sha1 -sign chave_privada.txt | openssl enc -A -base64")
       Log("/c echo.|set /p=" & Chr(34) & s_input & Chr(34) &" | openssl dgst -sha1 -sign chave_privada.txt | openssl enc -A -base64")
     
       params.Add(
    "/c")
       params.Add(
    "echo.|set")
       params.Add(
    ".|")
       params.Add(
    "set")
       params.Add(
    "/p=" & Chr(34) & s_input & Chr(34))
       params.Add(
    "|")
       params.Add(
    "openssl")
       params.Add(
    "dgst")
       params.Add(
    "-sha1")
       params.Add(
    "-sign")
       params.Add(
    "chave_privada.txt")
       params.Add(
    "|")
       params.Add(
    "openssl")
       params.Add(
    "enc")
       params.Add(
    "-A")
       params.Add(
    "-base64")

       shl.Initialize(
    "shl""cmd.exe", params)
       shl.WorkingDirectory = 
    File.DirApp
        
    Try
           
    ' Run with disabled timeout
           shl.Run(-1)
       
    Catch
           
    Log(LastException.Message)
       
    End Try
     
  2. Daestrum

    Daestrum Well-Known Member Licensed User

  3. Num3

    Num3 Member Licensed User

    @Daestrum I have the sub, posted below.
    It just reports:
    It should have reported:
    Code:
    Sub 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
        
    ExitApplication
    End Sub
     
  4. Daestrum

    Daestrum Well-Known Member Licensed User

    Is it a non-ui application ?
     
  5. Num3

    Num3 Member Licensed User

    It is UI, but need to use openssl to generate the hash for those strings.
    I have used this with success:
    Code:
    shl.Initialize("shl","cmd.exe",Array As String("/c echo. | openssl dgst -sha1 -sign chave_privada.txt < test1.txt | openssl enc -base64"))
    Instead of pipping the string into openssl i wrote it to a file (test1.txt), then pipped it's contents, but i would like to avoid writing it to a text file...
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    Why are you running cmd.exe instead of running openssl directly?
     
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