Results 1 to 10 of 11

Thread: How to redirect output of command called from OS_Shell()?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    How to redirect output of command called from OS_Shell()?

    I have a simple TB script which is a console mode script.

    In it, I us OS_Shell() to call another program. That other program outputs text to the console.

    Unfortunately, the output of the other program messes up the nice pretty output of my TB script in it's console.

    Is there a way to call another program from within TB such that the other program's console output does NOT get added to the TB console output?

    Thanks!

    *Brian

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Try redirect your shell command to NUL

    uses "OS"
    uses "console"
    
    
    OS_Shell("CMD.EXE /C DIR > NUL")
    WaitKey
    
    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
    Unfortunately, that appeared to have no effect. :-(

    Still get the extra output in my TB console.

    *Brian

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Redirecting into a file?

    If possible send me e little example showing what you are doing to better understand.

    support@thinbasic.com
    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

  5. #5
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Hello,

    I think you have to redirect both stderr and stdout.
    This could do it:
    uses "OS", "Console"
      
    OS_Shell("CMD.EXE /C dir > NUL 2>&1")
    WaitKey
    
    The 2>&1 looks strange, but it basically redirects stderr to stdout and that stdout you already send to NUL

    Let us know!


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  6. #6
    Hmm. That's a great suggestion, unfortunately it doesn't seem to work either.

    Without TB at all, if I just do this from the command line:

    C:\Users\bschmalz>C:\PEMicro\cyclone_stmicro\sap_launch port=USB1 IMAGE=1
    Success
    
    C:\Users\bschmalz>
    
    It's the "Success" that I don't want. That's the output of the sap_launch.exe program.

    If I do:

    C:\Users\bschmalz>C:\PEMicro\cyclone_stmicro\sap_launch port=USB1 IMAGE=1 > NULL 2>&1
    
    C:\Users\bschmalz>
    
    Then the result of the sap_launch program is not printed to the console. That worked, right?

    Not so fast. When I do this from within TB:

        OutputText("Cycle " + Using$("####",x) + " reprogramming = ")
        ' Send command to Cyclone to reprogram motherboard
        lProgResult = OS_Shell("C:\PEMicro\cyclone_stmicro\sap_launch port=USB1 IMAGE=1 > NULL 2>&1", %OS_WNDSTYLE_HIDE, %OS_SHELL_SYNC)
        OutputText(lProgResult + ", ")
        Delay(250)
        OutputText("power on, ")
    
    I get the following output:
    Cycle    1 reprogramming = Success
    0, power on,
    
    so there is something special about running within TB as compared to just running in a normal cmd window. I have tried different values for the 'WindowStyle' parameter in OS_Shell() as well, with no change in effect.

    This is on a Win 7 Pro machine.

    This is *not* a big deal to me at all. It's purely a cosmetic thing in the output of my program. Everything is actually working just fine, it's just not as pretty as it could be.

    *Brian

Similar Threads

  1. Console - function to be called at shutdown
    By Petr Schreiber in forum Suggestions/Ideas discussions
    Replies: 2
    Last Post: 12-03-2016, 13:31
  2. OS_Shell - question/issue
    By ReneMiner in forum OS
    Replies: 12
    Last Post: 16-09-2015, 22:44
  3. Replies: 2
    Last Post: 20-11-2014, 15:40
  4. Quote Of the Day Different output?
    By ErosOlmi in forum QOD: Question Of the Day
    Replies: 2
    Last Post: 08-02-2013, 09:44

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
  •