PDA

View Full Version : Will batch-commands mix with thinbasic-console?



ReneMiner
23-10-2019, 20:46
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?

jack
23-10-2019, 22:59
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

DirectuX
24-10-2019, 09:33
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.

10085

DirectuX
24-10-2019, 10:13
About setting environment variables, this article (http://www.dowdandassociates.com/blog/content/howto-set-an-environment-variable-in-windows-command-line-and-registry/) resumes the essential. You can run the commands through the H_run.run function by example.

ReneMiner
24-10-2019, 12:22
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

DirectuX
24-10-2019, 18:26
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.

ErosOlmi
24-10-2019, 20:30
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

Petr Schreiber
24-10-2019, 22:45
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

DirectuX
25-10-2019, 20:18
I have a question too,

how would you deal with console programs that have interactive mode ? (example (https://www.tutorialspoint.com/orientdb/orientdb_console_modes.htm))

DirectuX
25-10-2019, 20:25
@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.