Liberty BASIC Community Forum
« Getting feedback from cmd.exe »

Welcome Guest. Please Login or Register.
Jun 24th, 2017, 2:10pm


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Getting feedback from cmd.exe  (Read 255 times)
Mick
New Member
Image


member is offline

Avatar




PM


Posts: 7
xx Getting feedback from cmd.exe
« Thread started on: Jun 6th, 2016, 05:40am »

Hi all back again, having lost all my old e-mails!!! :(

Trying again to get data from a dos input by way of :-


IM$= "ipconfig/all"

run "cmd.exe /c "; chr$( 34); IM$; chr$( 34)

but can't for the life of me remember how to retain the dos output as a string, or even just save it as a txt file to read from later stages in the code.

many thanks in anticipation of assistance here.


User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is online

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5311
xx Re: Getting feedback from cmd.exe
« Reply #1 on: Jun 6th, 2016, 08:59am »

You need to pipe the data a file. This code reads %appdata% and outputs the dos result to a file > is the character than redirects the output to the named file.


Code:
'all of these files will be created in DefaultDir$
open "test.bat" for output as #test
#test "echo %APPDATA% > test.txt"
close #test
run "test.bat /q" ,hide
open "test.txt" for input as #test
line input #test, appdata$
close #test
appdata$=trim$(appdata$)+"\"
'use this variable in place of %APPDATA%
print appdata$



print DefaultDir$
result = mkdir( appdata$;"test")

open appdata$;"test\test.dat" for output as #1
#1 "hello"
close #1
open appdata$;"test\test.dat" for input as #1
i$=input$(#1,lof(#1))
 



More info here http://www.lagmonster.org/docs/DOS7/pipes.html
« Last Edit: Jun 6th, 2016, 09:00am by Rod » User IP Logged

Mick
New Member
Image


member is offline

Avatar




PM


Posts: 7
xx Re: Getting feedback from cmd.exe
« Reply #2 on: Jun 6th, 2016, 10:27am »

Thanks Rod, I'll take a look at that code again, but as I remember it it was much simpler and along the lines of :-


IM$= "ipconfig/all"
run "cmd.exe /c "; chr$( 34); IM$; chr$( 34) > test$
print test$
end

Unfortunately test$ doesn't seem to contain a string sad It's been a long while and I'm struggling to find my disks containing my old codes so am needing to start again sad



User IP Logged

tenochtitlanuk
Board Moderator

member is offline

Avatar




Homepage PM

Gender: Male
Posts: 1154
xx Re: Getting feedback from cmd.exe
« Reply #3 on: Jun 6th, 2016, 11:48am »

Following works on my Linux machines- watch for the space before '/all'.
Any use?
Code:
IM$     = "ipconfig /all"

cmd$    = IM$ + " > test.txt"

run cmd$

open "test.txt" for input as #fi
    f$ =input$( #fi, lof( #fi))
close #fi

print f$
end

 
User IP Logged

Mick
New Member
Image


member is offline

Avatar




PM


Posts: 7
xx Re: Getting feedback from cmd.exe
« Reply #4 on: Jun 6th, 2016, 1:37pm »

Oddly, No, runs the cmd side of the script no problems, test.txt remains blank cry

it'll be a simple error somewhere, I'll just go find a hammer and "fix" this aging lappy!!!
User IP Logged

cundo
Guru
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 620
xx Re: Getting feedback from cmd.exe
« Reply #5 on: Jun 7th, 2016, 09:07am »

Code:
IM$= "ipconfig /all"
run "cmd.exe /c "; chr$( 34); IM$; chr$( 34) ;" > test.txt"
end
 

Test is a text file. Must be between quotes including the > symbol.
With tenoch's print.
Code:
IM$= "ipconfig /all"
run "cmd.exe /c "; chr$( 34); IM$; chr$( 34) ;" > test.txt"
open "test.txt" for input as #fi
    f$ =input$( #fi, lof( #fi))
close #fi

print f$
end
 
User IP Logged

cundo
Mick
New Member
Image


member is offline

Avatar




PM


Posts: 7
xx Re: Getting feedback from cmd.exe
« Reply #6 on: Jun 7th, 2016, 10:35am »

Fantastic Cundo, That has me back on track.

Kind regards and may all your Gosubs Return smiley

User IP Logged

tenochtitlanuk
Board Moderator

member is offline

Avatar




Homepage PM

Gender: Male
Posts: 1154
xx Re: Getting feedback from cmd.exe
« Reply #7 on: Jun 7th, 2016, 10:51am »

That fails for me, cundo...
Why use cmd.exe to run ipconfig anway, rather than run it directly?
Never did like DOS commands or their successor command line ones...
User IP Logged

Mick
New Member
Image


member is offline

Avatar




PM


Posts: 7
xx Re: Getting feedback from cmd.exe
« Reply #8 on: Jun 7th, 2016, 10:59am »

It wasn't specifically for the IPconfig aspect, merely the obtaining usable data from any cmd prompt and placing in a file to be used later.

I've always had a fondness for Dos and batch files, just been so long now I'm considering a liberty based help sheet for syntax and switch reminders etc.
User IP Logged

Mystic
Junior Member
ImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 97
xx Re: Getting feedback from cmd.exe
« Reply #9 on: Jun 7th, 2016, 11:14am »

This helped me remove some "lazy" code from me in one of my programs. I was just creating a batch file and running the batch file. smiley

Thanks!
User IP Logged

- Rick
Programming BASIC since the 80's starting with a TRS-80.
Mick
New Member
Image


member is offline

Avatar




PM


Posts: 7
xx Re: Getting feedback from cmd.exe
« Reply #10 on: Jun 7th, 2016, 11:49am »

yes, tenochtitlanuk it does work, but for me, only on the second pass, for some reason one can't immediately open a file only just written in the same code :S

User IP Logged

cundo
Guru
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 620
xx Re: Getting feedback from cmd.exe
« Reply #11 on: Jun 7th, 2016, 9:41pm »

Try adding a SLEEP, or a file exist routine. Maybe both.
User IP Logged

cundo
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls