Results 1 to 5 of 5

Thread: Capturing OS_ShellExecute Output?

  1. #1

    Capturing OS_ShellExecute Output?

    I searched and didn't find many posts on OS_ShellExecute, and the manual only has minimal information on this. I'm assuming the information returned from it is NOT the output, but rather some sort of status code (I get "42" back from nbtscan.exe, and I don't think this is the answer I'm looking for!).

    Is the only way to capture the output of a command line executable to redirect to the output to a file and then read in the file? (painful if you are running lots of commands!)

    This is what I'm trying to run:

    [code=thinbasic]USES "File"
    uses "Console"
    uses "OS"

    Dim FileToLoad as integer
    dim MyArray() as asciiz
    dim nLines as long
    dim nCols as long
    dim CountLine as long
    dim CountCol as long
    dim sTemp AS ASCIIZ

    Console_Writeline("Test Console App")

    REM Stores.csv is a list of StoreNumber,VLAN1IPAddress,VLAN2IPAddress
    PARSE(FILE_Load("M:\Misc\Matt\CanadianInventory\Data\Stores.csv"), MyArray(), $crlf , ",")

    nLines = ubound(MyArray(1))
    nCols = ubound(MyArray(2))

    console_writeline("Total number of lines : " & nLines)
    console_writeline("Total number of colums: " & nCols)

    for CountLine = 1 to nLines
    sTemp = OS_SHELLEXECUTE ( "open", "nbtscan.exe", MyArray(CountLine,2) + "/24", "", %OS_WNDSTYLE_NORMAL)
    console_writeline(sTemp)
    next
    [/code]

    Thanks,
    Matt


  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: Capturing OS_ShellExecute Output?

    Matt,

    what about this one:
    [code=thinbasic]
    USES "File"
    uses "Console"
    uses "OS"

    Dim FileToLoad as integer
    dim MyArray() as string '<<<<< Changed to STRING. ASCIIZ are used only with fized size usually
    dim nLines as long
    dim nCols as long
    dim CountLine as long
    dim CountCol as long
    dim sTemp AS ASCIIZ

    Console_Writeline("Test Console App")

    REM Stores.csv is a list of StoreNumber,VLAN1IPAddress,VLAN2IPAddress
    PARSE(FILE_Load("M:\Misc\Matt\CanadianInventory\Data\Stores.csv"), MyArray(), $crlf , ",")

    nLines = ubound(MyArray(1))
    nCols = ubound(MyArray(2))

    console_writeline("Total number of lines : " & nLines)
    console_writeline("Total number of colums: " & nCols)

    '---This will contain the full captured buffer
    dim sBuffer as string

    for CountLine = 1 to nLines
    OS_Shell(OS_ENVIRON("COMSPEC") & " /C " & app_sourcepath & "nbtscan.exe " & MyArray(CountLine,2) & "/24 > " & app_sourcepath & "__Out__.txt", %OS_WNDSTYLE_HIDE, %OS_SHELL_SYNC)
    '---At every RUN, output will be deleted, so we accumulate into sBuffer
    sBuffer += file_load(app_sourcepath & "__Out__.txt") & repeat$(80, "-") & $crlf
    next
    '---At the end, sBuffer will contain the full scan
    msgbox 0, sBuffer
    [/code]

    Capturing the output buffer is not so trivial. We need to create a process manually using Win32 API telling we want to have stdout captured into a file handle. Than we need to create a new file handle, close at the end, get the output manually, ...

    Much better it seems to me to have a output file redirection into a temp file. When OS_SHELL finish, capture the output and a new loop with a different net scan will start.

    What do you think?

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  3. #3
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: Capturing OS_ShellExecute Output?

    Please change
    [code=thinbasic]dim MyArray() as asciiz[/code]
    to
    [code=thinbasic]dim MyArray() as STRING[/code]

    Seems there is a problem in PARSE function when dealing with ASCIIZ strings. Not sure but NULL terminator is not added.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  4. #4

    Re: Capturing OS_ShellExecute Output?

    Yes, this is a little longer, but works very well. I understand it isn't trivial to capture the output, but you seem to have worked so many other miracles in this little language, that since I didn't see it in the docs, I just had to ask.

    Thanks again,
    Matt

  5. #5
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: Capturing OS_ShellExecute Output?

    Well, we are making our best for the "impossible" but we are not yet organized for "miracles" ;D

    Feel free to ask whatever you need here. That is a must.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

Similar Threads

  1. using os_shellexecute
    By sandyrepope in forum OS
    Replies: 2
    Last Post: 26-11-2007, 10:43

Members who have read this thread: 2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •