我想知道如何在QBasic中运行批处理文件。
当我的意思是在我内心意味着不是在一个新的窗口。
你可以帮帮我吗?我做了一个虚假的DOS。
答案 0 :(得分:2)
我找不到在同一窗口中专门运行dos命令的方法。你可以做的是SHELL _HIDE" [command]> outputfile.txt"然后打开该文件并将每行打印到您的qb应用程序。
示例并不完美,但可以作为开始的基础:
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