Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Executing system command and getting output

Author
Message
Statue
19
Years of Service
User Offline
Joined: 16th Nov 2006
Location: Monterey Hills, CA
Posted: 3rd Mar 2012 11:07
Hello All:

I was wondering if there was a way with DBPro, to get the output from a system command into DBPro. For example, two commands I'd like are:

set temp
net user

I've tried doing id=execute executable("net.exe user >c:\bob","",""), however it does not output to c:\bob. I've also tried execute file with the same result. It'd be doubly-lame if I had to use DBPro to build a batch file to create the output file, execute it, then have to read the output back in.

I have Extends, but don't know if that helps.

It would be great if there was the equivalent to the following PERL command:

@mydata=system("net user");

Lance
Sergey K
22
Years of Service
User Offline
Joined: 4th Jan 2004
Location:
Posted: 3rd Mar 2012 19:03 Edited at: 3rd Mar 2012 19:05
as you know, all the system commands (or other words, files) are placed at the system directory. just follow this code:

sysdir$ = windir$()+"\system32\"
file$ = "net.exe"
command$ = "user >c:\bob"

execute file sysdir$+file$,command$,""

//this should do it.

and about the output, the best way i can think of, is to add an extra line that exports the command line into a file, then let dbpro read the file.

more 3d models .x/.obj and more foramts here:
[href]https://www.turbosquid.com/Search/Index.cfm?keyword=gogetax1&x=0&y=0[href]
Statue
19
Years of Service
User Offline
Joined: 16th Nov 2006
Location: Monterey Hills, CA
Posted: 3rd Mar 2012 20:05
Thanks Sergey - I will give it a try, but is there a better way than outputting to a file then reading a file - it'd be great it I could just do a net.exe user and somehow get the result in an array directly in DB Pro...

Lance
Sergey K
22
Years of Service
User Offline
Joined: 4th Jan 2004
Location:
Posted: 3rd Mar 2012 23:03
dark basic maybe a basic languange, but i dont think there is a way to do it simpeler..

more 3d models .x/.obj and more foramts here:
[href]https://www.turbosquid.com/Search/Index.cfm?keyword=gogetax1&x=0&y=0[href]
Statue
19
Years of Service
User Offline
Joined: 16th Nov 2006
Location: Monterey Hills, CA
Posted: 5th Mar 2012 05:09
Hello Sergey:

The code you provided didn't work. Not sure, but I think it's running the net user command, but not producing the c:\bob output file.

Lance
Sergey K
22
Years of Service
User Offline
Joined: 4th Jan 2004
Location:
Posted: 5th Mar 2012 17:58
ok, not sure why it didnt worked, but never mind that.
here is a quick tutorial i made for you how to export every command into dark basic:




basiclly, it creates a .bat file and executes it.
inside the bat file there is an output to file command.
then DBP waits for any new file created and reads it.

thats basicly it.

more 3d models .x/.obj and more foramts here:
[href]https://www.turbosquid.com/Search/Index.cfm?keyword=gogetax1&x=0&y=0[href]
Statue
19
Years of Service
User Offline
Joined: 16th Nov 2006
Location: Monterey Hills, CA
Posted: 8th Mar 2012 05:27
Hello Sergey:

What about getting rid of the DOS popup? For example, if you execute the batch file with the command "start /b batchfile.bat" there is no popup?

Lance
Sergey K
22
Years of Service
User Offline
Joined: 4th Jan 2004
Location:
Posted: 8th Mar 2012 22:33
i never got into those stuff before..
but why do u need to execute system commands? all of the commands you can program your self in dark basic pro. if no, you always can call some of the system dlls for that.

what command you want to call again? and what it does? maybe i can point you to right direction..

more 3d models .x/.obj and more foramts here:
[href]https://www.turbosquid.com/Search/Index.cfm?keyword=gogetax1&x=0&y=0[href]
Statue
19
Years of Service
User Offline
Joined: 16th Nov 2006
Location: Monterey Hills, CA
Posted: 8th Mar 2012 22:59
Hello Sergey:

I am calling a diagnostic program for SAN client software. The client itself doesn't have certain functionality I need, however the diagnostic program does. I am writing a control interface which supplements the client software by calling the diagnostic program. I also need to get a bunch of other system info, such as the current user, and complete user list, so I create a batch file to do all this, which executes from DBPro, producing a data file which I can read in.

Lance
Sergey K
22
Years of Service
User Offline
Joined: 4th Jan 2004
Location:
Posted: 8th Mar 2012 23:08
i see.
but Unfortunately i cant help you with those stuff.
but i can suggest you to move on from dark basic to some other languange such as visual basic to do all of those stuff.
dark basic is for game making..

more 3d models .x/.obj and more foramts here:
[href]https://www.turbosquid.com/Search/Index.cfm?keyword=gogetax1&x=0&y=0[href]
Statue
19
Years of Service
User Offline
Joined: 16th Nov 2006
Location: Monterey Hills, CA
Posted: 8th Mar 2012 23:45
Hello Sergey:

Visual Basic does not provide the interactivity I need in the user interface.

Lance
Statue
19
Years of Service
User Offline
Joined: 16th Nov 2006
Location: Monterey Hills, CA
Posted: 8th Mar 2012 23:47
Plus one rule is that the client can't install anything else other than my executable...
Sergey K
22
Years of Service
User Offline
Joined: 4th Jan 2004
Location:
Posted: 9th Mar 2012 00:38
Quote: "Visual Basic does not provide the interactivity I need in the user interface.
"


yes it does.
1) make the form black
2) use image buttons for the buttons
and you also can use some directx components with in it. little bit harder to setup the directx window, but its all possible.


Quote: "Plus one rule is that the client can't install anything else other than my executable..."

i belive you can include all the media into one exe. not sure how, but it never been a problem to good respected programming languanges..

more 3d models .x/.obj and more foramts here:
[href]https://www.turbosquid.com/Search/Index.cfm?keyword=gogetax1&x=0&y=0[href]
jestermon
15
Years of Service
User Offline
Joined: 26th Nov 2010
Location:
Posted: 12th Mar 2012 10:17
A simple solution around the .bat pop-up windows problem, is to use a batch to exe file converter. I use Bat_To_Exe_Converter from http://www.f2ko.de. It's free and it does a great job.

Steps
1.. create a .cmd or .bat file that you need to do the job - With all the > output to file you need
2.. Convert the file to an exe - Select the "Invisible Application" option to ensure you have no command windows popping up all over the place to mess up your full screen app
3.. Call (System-run) the new exe from DPB
4.. read the output file into your DBP app

have fun
Statue
19
Years of Service
User Offline
Joined: 16th Nov 2006
Location: Monterey Hills, CA
Posted: 12th Mar 2012 15:43
Hello Apollo:

I'll give it a try, but the problem will be legal this time: I would have to include the battoexe converter with the app, as the batch file is generated in real-time, my program may be commercial, and I don't know if the people who wrote battoexe will allow this.

Lance
jestermon
15
Years of Service
User Offline
Joined: 26th Nov 2010
Location:
Posted: 13th Mar 2012 21:46
Who's Apollo?

Anyway, the easiest way to get around a cmd file opening a console widow is as follows - without distributing anyone else's software

Steps to prepare
1.. Create a .cmd file named 'batshell.cmd'
2.. Paste the following line into it
wscript.exe "invis.vbs" "batrun.bat"
3.. Compile the file to exe with 'invisible application' using bat_to_exe
4.. Create a vbscript file named "invis.vbs"
5.. Paste the following line into it
CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False
6.. Create a .bat file named "batrun.bat"
7.. Paste the following line into it
echo hello world > outfile.txt
8.. Run the batshell.exe
You will see a textfile "outfile.txt" with the text "hello world" in it

Steps to use
1.. From your program write out your bat command lines to "batrun.bat"
2.. Call batshell.exe from your program
Everything will run invisibly, and batrun.bat will do whatever you wish
Distribute only batshell.exe and invis.vbs with your app.

Login to post a reply

Server time is: 2026-07-10 01:06:33
Your offset time is: 2026-07-10 01:06:33