2

I would like to know how to run a batch file within QBasic.

And when I mean within I mean NOT in a new window.

Can you help me out?

I'm making a fake DOS.

BuzzyBlitz
  • 55
  • 3

1 Answers1

2

I cannot find a way to specifically run dos commands in the same window. What you can do is SHELL _HIDE "[command] > outputfile.txt" and then open that file up and print out each line to your qb app.

Example is not perfect but could be used as a base to get going:

RunCommand "dir"
END

SUB RunCommand (enteredCommand$)
    IF LEN(enteredCommand$) = 0 THEN EXIT FUNCTION 'no entry
    IF LEN(ENVIRON$("OS")) THEN CMD$ = "CMD /C " ELSE CMD$ = "COMMAND /C "
    SHELL _HIDE CMD$ + enteredCommand$ + " > output"
    OPEN "output" FOR APPEND AS #1 'this may create the file
    L% = LOF(1) 'verify that file and data exist
    CLOSE #1

    IF L% THEN 'read file if it has data
        OPEN "output" FOR INPUT AS #1
        WHILE NOT EOF(1)
            LINE INPUT #1, line$ 'read only line in file
            PRINT line$
        WEND
        CLOSE #1
    ELSE
        PRINT "Command Not Found" 'returns zero length string if path not found
    END IF
    KILL "output" 'deleting the file is optional
END FUNCTION
CarCar
  • 680
  • 4
  • 13
  • Your answer would be more helpful if you could decide if the double-quotes are required or not - or explain when they are required. – Blackwood Aug 18 '15 at 00:50