Try redirect your shell command to NUL
uses "OS" uses "console" OS_Shell("CMD.EXE /C DIR > NUL") WaitKey
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
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
Unfortunately, that appeared to have no effect. :-(
Still get the extra output in my TB console.
*Brian
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
Hello,
I think you have to redirect both stderr and stdout.
This could do it:
The 2>&1 looks strange, but it basically redirects stderr to stdout and that stdout you already send to NULuses "OS", "Console" OS_Shell("CMD.EXE /C dir > NUL 2>&1") WaitKey
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
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:
It's the "Success" that I don't want. That's the output of the sap_launch.exe program.C:\Users\bschmalz>C:\PEMicro\cyclone_stmicro\sap_launch port=USB1 IMAGE=1 Success C:\Users\bschmalz>
If I do:
Then the result of the sap_launch program is not printed to the console. That worked, right?C:\Users\bschmalz>C:\PEMicro\cyclone_stmicro\sap_launch port=USB1 IMAGE=1 > NULL 2>&1 C:\Users\bschmalz>
Not so fast. When I do this from within TB:
I get the following output: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, ")
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.Cycle 1 reprogramming = Success 0, power on,
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
Is your thinBasic script a .tBasic or .tbasicc extension?
When using .tbasic extension you are executing thinbasic.exe GUI version (even if you use "Console" module)
When using .tbasicc extension you are executing thinbasicc.exe Console version
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
Let's see if I get it
Attached File and Console module updated. Download and unzip in \thinBasic\Lib\ directory replacing your current one.
I've added a new File function (File_Attr) and fixed an undocumented Console function (Console_SetStdHandle) that I will release in next thinBasic version
Mainly before you want to avoid to get standard output of you shelled application be printed in your console screen, you create a dummy file and redirect standard output into that dummy file
Let me know if it works
Here an example on how to proceed
uses "Console"uses "OS" uses "file" long X long lProgResult '---Redirect standard output into a dummy file LOCAL hFile AS LONG local hSys AS LONG string sOutFile = "My_stdout.txt" hFile = FILE_Open(sOutFile, "output") hSys = FILE_Attr(hFile,2) ' get system handle Console_SetStdHandle(%CONSOLE_STD_OUTPUT_HANDLE, hSys) ' make this file the STDOUT for this process for x = 1 to 2 OutputText("Cycle " + Using$("####",x) + " reprogramming = ") ' Send command to Cyclone to reprogram motherboard lProgResult = OS_Shell("_______HERE YOUR SHELL COMMAND _____________", %OS_WNDSTYLE_HIDE, %OS_SHELL_SYNC) OutputText(lProgResult + ", ") Delay(250) OutputText("power on, ") Next '---Close redirection FILE_Close(hFile) OutputText("---End---") WaitKey function OutputText(byval sText as string) printl sText end Function function delay(byval mSec as long) sleep mSec end Function
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
Ah! Maybe that's the ticket! I was using .tbasic.
However, if I switch to .tbasicc, and run it, I get the following:
Note the "Success", so that change didn't solve the problem.D:\Projects\CSIEE\PIGrapher>CycloneCRCCorruptionTest.tbasicc Programming CRC Corruption Test program v1.0 started on 2018-03-08 08:00:44 Opening relay COM84 ...open relay port ok. Opening command COM4 ...open command port ok. Cycle 1 reprogramming = Success 0, power on, power off, delaying 2s, testing, power off passed. Cycle 2 reprogramming = Success 0, power on, power off, delaying 2s, testing, power off passed. Command COM port now closed Relay COM port now closed Press any key to exit
*Brian
And you've gone and done it again Eros! This solution totally solves the problem. When I followed your instructions above, I get the following as output:
Programming CRC Corruption Test program v1.0 started on 2018-03-08 08:41:35 Opening relay COM84 ...open relay port ok. Opening command COM4 ...open command port ok. Cycle 1 reprogramming = 0, power on, power off, delaying 2s, testing, power off passed. Cycle 2 reprogramming = 0, power on, power off, delaying 2s, testing, power off passed. Command COM port now closed Relay COM port now closed Press any key to exit
Which is exactly how it should be. Nice and clean.
Thank you SO MUCH!!
*Brian
Bookmarks