Results 1 to 10 of 10

Thread: Will batch-commands mix with thinbasic-console?

  1. #1
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,544
    Rep Power
    172

    Will batch-commands mix with thinbasic-console?

    Hi Guys,
    I have an question how-to....
    I want to process some windows-console commands and thinbasic-console-scripts are easier to handle , especially vaiables-handling etc.
    Now my question: can thinbasic call command-line Tools that are built-in or are additional shipped with Windows:
    How can i open thinbasic-console as Administrator?
    And how would i use batch commands then, for example "xcopy" -
    Would i have to declare xcopy somehow or could i Just use it in tb-console-script?
    And other things as fsutil, DISM or whatever commands are delivered and built-in to Windows, are they usable without lots of effort, wrapping etc. and the Environment-Variables of windows are available too for get & set ? or does it require to use the registry to access windows-values like %homedrive%, %systemroot% or %app_data%. Or will i have to declare absolute variables in thinbasic on the adress of the windows-values?

    Can i for example

    Start cmd.exe /c "cmd /c Echo hello World!" %*


    to start the command prompt to say "Hello World!" with Administrator-privileges (%*)? IsThere a Tutorial or some written experience about this matter?
    Last edited by ReneMiner; 23-10-2019 at 20:50.
    I think there are missing some Forum-sections as beta-testing and support

  2. #2
    Hi Rene
    perhaps in this case another tool would be appropriate, how about https://www.autohotkey.com ?
    I have never used it because I never had a need, but it may suit your needs

  3. #3
    Hi Rene,

    Long ago, I started (it's not finished) to program something about this for my project. Maybe it is a part of what you look for, watch at the H_run function in the attached file. For the "admin" part, I don't know, maybe you have just to start thinBasic as admin.

    HELPERS2.tbasic
    ThinBasic 1.11.6.0 ALPHA - Windows 8.1 x64

  4. #4
    About setting environment variables, this article resumes the essential. You can run the commands through the H_run.run function by example.
    ThinBasic 1.11.6.0 ALPHA - Windows 8.1 x64

  5. #5
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,544
    Rep Power
    172
    Thank you .it Shows me a Bit different waY how to solve things. And using OS_shell is pretty straighforward. I wanted more the way to let everything happen within tB-console-window, even the Output of the command prompt as well as typing and sending <expressions> through thinbasic console but it should be very easy to direct anything that the interpreter can not understand instantly to OS. Only capturing the Output from OS-functions and scripts seems bit Tricky now. I guess it needs to create a shortcut to %comspec% - i.e. cmd.exe that will just echo everything to a text-file or Something Like that. Anyway it Shows me another way that ist possible for Sure. Thanks
    I think there are missing some Forum-sections as beta-testing and support

  6. #6
    Quote Originally Posted by ReneMiner View Post
    I guess it needs to create a shortcut to %comspec% - i.e. cmd.exe that will just echo everything to a text-file or Something Like that.
    I didn't understand that part. If you're talking about the piece of code above, there's not prerequisite* : just pass to the function a string containing what you would have typed in the windows command-line interpreter and it returns a string containing the output of the command. No text-file needed either.

    Edit: I've just seen that you need to uncomment this code in the function :
    'if Function_CParams = 1 Then
      '  Me.CommandLine = sCommandLine
      'endif
    
    that's because at this time Function_CParams was buggy, but Eros did correct it in newer versions of ThinBasic.


    * unless C:\Windows\System32 is not already in your PATH.
    Last edited by DirectuX; 24-10-2019 at 19:04.
    ThinBasic 1.11.6.0 ALPHA - Windows 8.1 x64

  7. #7
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,795
    Rep Power
    10
    New thinBasic version 1.11.2 that will be available in few weeks will have a Shell_CaptureOutput function able to execute a console command and capture its output into a string.
    Something like:
       Function Shell_CaptureOutput ( _
                                      ByVal CmdLine             As String, _
                                      ByVal StartDirectory      As String, _
                                      ByRef sResult             As String, _
                                      ByVal dwMillisecondsWait  As Dword _
                                    ) As Long
    
    @DirectuX: your HELPERS2.tbasic example posted above is very interesting.
    Can I use in thinBasic distribution as standard example?

    Thanks
    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

  8. #8
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,138
    Rep Power
    733
    Eros,

    may I have a wish - could Shell_CaptureOutput please capture both STDOUT and STDERR? Some programs log to STDERR, for example.

    I propose this signature:
    Function Shell_CaptureOutput ( _
                                   ByVal CmdLine             As String, _
                                   ByVal StartDirectory      As String, _
                                   ByRef StdOut              As String, _
                                   ByRef StdErr              As String, _
                                   ByVal dwMillisecondsWait  As Dword _
                                 ) As Long
    
    Petr
    Last edited by Petr Schreiber; 25-10-2019 at 07:15.
    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

  9. #9
    I have a question too,

    how would you deal with console programs that have interactive mode ? (example)
    ThinBasic 1.11.6.0 ALPHA - Windows 8.1 x64

  10. #10
    Quote Originally Posted by ErosOlmi View Post
    @DirectuX: your HELPERS2.tbasic example posted above is very interesting.
    Can I use in thinBasic distribution as standard example?

    Thanks
    Sure you can. Do you intend to use only a portion ? I ask this because it isn't finished nor cleaned: OOP isn't effective yet and at least the function needs adding a comment about system32 folder in PATH. Anyway, do like you need Eros.
    ThinBasic 1.11.6.0 ALPHA - Windows 8.1 x64

Similar Threads

  1. Suggestion: new for commands
    By kryton9 in forum Suggestions/Ideas discussions
    Replies: 7
    Last Post: 16-05-2017, 19:15
  2. batch (.bat) files
    By sandyrepope in forum General
    Replies: 9
    Last Post: 24-07-2008, 16:14

Members who have read this thread: 1

Tags for this Thread

Posting Permissions

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