Command prompt problem (SHELL)

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
Sinuvoid
Veteran
Posts: 155
Joined: Wed Jul 25, 2007 8:20 am

Command prompt problem (SHELL)

Post by Sinuvoid »

Ok guys, another problem. When my command prompt command runs it give me a bad command or file name error. and the stynax and file are both completely right. heres the code. (PS. name 4 files like the ones in the code to get teh same results as me)

Code: Select all

DECLARE SUB Stopp ()
'Actor database of ZSO
DEFINT A-Z
CLS

'sets up backround
Wbackround:
FOR i = 1 TO 30
COLOR 15, 12
LOCATE 15, 20
PRINT "Loading, Please wait."
FOR b = 1 TO 30
NEXT b
CLS
LOCATE 15, 20
PRINT "Loading, Please wait.."
FOR b = 1 TO 30
NEXT b
CLS
LOCATE 15, 20
PRINT "Loading, Please wait..."
FOR b = 1 TO 30
NEXT b
CLS
NEXT i

'Information
CLS
test:
COLOR 15, 12
LOCATE 1, 1
PRINT "A production of Souylsin."
SLEEP 1
LOCATE 2, 1
PRINT "Production date: Tuesday, November 27th/07."
LOCATE 3, 1
PRINT "Thanks to all who contributed to this project."
SLEEP 1
LOCATE 4, 1
PRINT "ZSO DAT 0.01"
SLEEP 1
LOCATE 5, 1
PRINT "Please make sure all files are in same folder..."
LOCATE 6, 1
PRINT there$
LOCATE 7, 1
LOCATE 8, 1
PRINT "TEST COMPLETE"
LOCATE 11, 1
PRINT "Press Any key to Continue"
DO
kp$ = INKEY$
IF kp$ <> "" THEN GOTO menu
LOOP

'the main menu
menu:
CLS
LOCATE 5, 20
COLOR 15, 12
PRINT "The Offline Wiki"
LOCATE 7, 20
COLOR 10, 12
PRINT "(S)earch for Actors"
LOCATE 9, 20
PRINT "(T)utorials"
LOCATE 11, 20
PRINT "(G)ameshark Codes"
COLOR 15, 12
LOCATE 15, 20
PRINT "(E)xit"

DO
kp$ = INKEY$
IF kp$ = "t" THEN GOTO tuts
IF kp$ = "g" THEN GOTO GSC

IF kp$ = "s" THEN
acts = 0
acts = acts + 1
GOTO asearch
END IF

IF kp$ = "e" THEN GOTO ext
LOOP

'starts the search engine, and fixes it to the correct settings
asearch:
CLS

act$ = "Actordat.txt"
gs$ = "GSC.txt"
data$ = CHR$(0)

IF gscs = 1 THEN
data$ = gs$
GOTO searchprog
END IF

IF acts = 1 THEN
data$ = act$
GOTO searchprog
END IF

searchprog:
LOCATE 1, 1
COLOR 15, 12
INPUT "Part of whole of file:", sactname$
cmd$ = "FIND /I " + CHR$(34) + sactname$ + CHR$(34) + " " + data$
SHELL cmd$
PRINT "(A)nother search or (M)enu?"

DO
kp$ = INKEY$
IF kp$ = "a" THEN GOTO asearch
IF kp$ = "m" THEN
gscs = 0
acts = 0
GOTO menu
END IF
LOOP

'tutorial menu
tuts:
CLS

COLOR 15, 12
LOCATE 10, 20
PRINT "Choose a Tutorial"
LOCATE 12, 20
PRINT "(1)DL's Exit Tutorial"
LOCATE 14, 20
PRINT "(2)DL's Porting Tutorial"
LOCATE 17, 20
PRINT "(E)xit"
DO
kp$ = INKEY$
IF kp$ = "1" THEN
tut = 0
tut = 1
GOTO oall
END IF
IF kp$ = "2" THEN 
tut2 = o
tut2 = 1
GOTO oall
END IF
IF kp$ = "e" THEN GOTO menu
LOOP

'gameshark code menu
GSC:
CLS
COLOR 15, 12
LOCATE 10, 13
PRINT "Would you like to"
LOCATE 12, 13
PRINT "(1)Search for GS codes"
LOCATE 13, 13
PRINT "(2)Print them all?"
LOCATE 14, 13
PRINT "(E)xit"

DO
kp$ = INKEY$
IF kp$ = "1" THEN
gscs = 0
gscs = gscs + 1
GOTO asearch
END IF
IF kp$ = "2" THEN
gscs = 0
gscs = gscs + 1
GOTO oall
END IF
LOOP

'prints/opens a whole file
oall:
CLS
DO

f$ = ""
IF gscs = 1 THEN
f$ = "GSC.txt"
gscs = 0
GOTO aftr
END IF
IF tut1 = 1 THEN
f$ = "DLET.txt"
tut1 = 0
GOTO aftr
END IF
IF tut2 = 1 THEN
f$ = "DLPT.txt"
tut2 = 0
GOTO aftr
END IF

aftr:
cmd2$ = "start /MAX notepad " + CHR$(34) + f$ + CHR$(34)
SHELL cmd2$

Stopp

GOTO menu

LOOP

'exit program
ext:
CLS
RANDOMIZE TIMER
C = INT(RND * 0 + 15) + 1
COLOR C
LOCATE 10, 25
PRINT "BYE!"
SLEEP 1
END

SUB Stopp
PRINT "Program Paused"
DO
kp$ = INKEY$
IF kp$ <> "" THEN GOTO contin
LOOP
contin:
END SUB

Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post by Nodtveidt »

This is a rather advanced solution, but might be the only thing that works for you.

While writing a video conversion utility just recently, I was having a similar problem; a shell command that refused to work despite the syntax being absolutely correct. My solution was to create a batch file instead and shell to THAT. Basically, just create a file with the OUTPUT file mode and put whatever command you want to execute into the file, then SHELL to the batch file you just created. Quick example:

Code: Select all

DIM FH AS INTEGER
FH = FREEFILE
OPEN "MYCMD.BAT" FOR OUTPUT AS #FH
PRINT #FH, "@FIND /I " + CHR$(34) + sactname$ + CHR$(34) + " " + data$
CLOSE FH
SHELL "MYCMD.BAT"
Also, make SURE that you use PRINT # and not WRITE # because the latter will quote the whole string and brick the command. Furthermore, the @ at the beginning will prevent echoing of the command itself (so you don't see the line show up in the console).
Sinuvoid
Veteran
Posts: 155
Joined: Wed Jul 25, 2007 8:20 am

Post by Sinuvoid »

Yeah figured out the problem...I had the variable turning back into a 0 and not 1...but that batch file idea will help probably one day :P
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

OK Girls!

Post by burger2227 »

You sound like my daughter when she turned 12!

OK guys? That sounds like my boss giving me a job to do!

Knock it off! You are not my boss or my daughter and I noticed that THANKS is pretty hard for you to say.

We can help, but we do not HAVE to! And make sure that you really need help by checking your own code first.

Ted
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
Sinuvoid
Veteran
Posts: 155
Joined: Wed Jul 25, 2007 8:20 am

Post by Sinuvoid »

Hey, sorry burger...Actually Im still having the problem...I tried that batch file technique but still no cigar...Can you please help me?
User avatar
Seb McClouth
Veteran
Posts: 342
Joined: Wed Nov 09, 2005 7:47 am
Location: Inside the Matrix...
Contact:

Post by Seb McClouth »

Where you stuck? If you can tell us how far you gotten, it's easier to get a hold of the problem and solve it.
QBinux is a Linux distribution with the aim of integrating the work of the vast community of free software developers at Pete's QBASIC Site in order to create a modern, performant, safe and easy to use system for system administrators and desktop users.
Sinuvoid
Veteran
Posts: 155
Joined: Wed Jul 25, 2007 8:20 am

Post by Sinuvoid »

Ok, heres my code now... Im stuck with the command prompt part where is opens a file.

Code: Select all

DECLARE SUB Delay (Secs!)
DECLARE SUB Intftut ()
DECLARE SUB IntfGSC ()
DECLARE SUB Menuf ()
DECLARE SUB Buttoncc ()
DECLARE SUB SCREENF ()
DECLARE SUB Interface ()
DECLARE SUB Exitm ()
DECLARE SUB Backroundf ()
DECLARE SUB Stopp ()
'Actor database of ZSO
DEFINT A-Z
CLS

'sets up backround
Wbackround:
Backroundf
'Sets up screen

'Information
CLS
test:
COLOR 12
LOCATE 13,14
startupm
Stopp

'the main menu
Menu:
CLS
COLOR 12
Interface
Menuf

DO
kp$ = INKEY$
acts = 0
IF kp$ = "1" THEN
acts = 1
LOCATE 7, 19
COLOR 12
PRINT "*(1)Search for Actors*"
Delay .3
GOTO asearch
END IF

IF kp$ = "2" THEN
COLOR 12
LOCATE 9, 19
PRINT "*(2)Tutorials*"
Delay .3
GOTO tuts
END IF

IF kp$ = "3" THEN
COLOR 12
LOCATE 11, 19
PRINT "*(3)Gameshark Codes*"
Delay .3
GOTO GSC
END IF

IF kp$ = "4" THEN
COLOR 15
LOCATE 15, 19
PRINT "*(4)Exit*"
Delay .3
Exitm
END IF

IF kp$ = "9" THEN
SCREEN 12
FOR h = 1 TO 1500
LOCATE 1, 73
COLOR 15
PRINT "[" + CHR$(19) + "]"
NEXT h
COLOR 12
Interface
Menuf
END IF

IF kp$ = "0" THEN
FOR h = 1 TO 2000
LOCATE 1, 77
COLOR 15
PRINT "[X]"
NEXT h
COLOR 12
LOCATE 1, 77
PRINT "[X]"
Exitm
END IF
LOOP

'starts the search engine, and fixes it to the correct settings
asearch:
CLS

act$ = "Actordat.txt"
gs$ = "GSC.txt"
data$ = CHR$(0)

IF gscs = 1 THEN
data$ = gs$
GOTO searchprog
END IF

IF acts = 1 THEN
data$ = act$
GOTO searchprog
END IF

searchprog:
SCREEN 0
LOCATE 1, 5
COLOR 12
Interface
INPUT "Search for Part of/ file:", sactname$
cmd$ = "FIND /I " + CHR$(34) + sactname$ + CHR$(34) + " " + data$
SHELL cmd$
PRINT "(1)Another search or (2)Menu?"

DO
kp$ = INKEY$
IF kp$ = "1" THEN GOTO asearch
IF kp$ = "2" THEN
gscs = 0
acts = 0
GOTO Menu
END IF

IF kp$ = "9" THEN
SCREEN 12
LOCATE 1, 73
COLOR 15
PRINT "[" + CHR$(19) + "]"
Delay 0.5
COLOR 12
Interface
Menuf
END IF

IF kp$ = "0" THEN
LOCATE 1, 77
COLOR 15
PRINT "[X]"
Delay .5
COLOR 12
LOCATE 1, 77
PRINT "[X]"
Exitm
END IF
LOOP

'tutorial menu
tuts:
CLS
COLOR 12
Interface
Intftut

DO
kp$ = INKEY$
tut = 0
tut2 = 0

IF kp$ = "1" THEN
tut = 1
COLOR 12
LOCATE 7, 19
PRINT "*(1)DL's Exit Tutorial*"
Delay 0.5
GOTO oall
END IF

IF kp$ = "2" THEN
tut2 = 1
COLOR 12
LOCATE 9, 19
PRINT "*(2)DL's Porting Tutorial*"
Delay 0.5
GOTO oall
END IF

IF kp$ = "3" THEN GOTO Menu

IF kp$ = "9" THEN
SCREEN 12
LOCATE 1, 73
COLOR 15
PRINT "[" + CHR$(19) + "]"
Delay 0.5
COLOR 12
Interface
Menuf
END IF

IF kp$ = "0" THEN
LOCATE 1, 77
COLOR 15
PRINT "[X]"
Delay 0.5
COLOR 12
LOCATE 1, 77
PRINT "[X]"
Exitm
END IF
LOOP

'gameshark code menu
GSC:
CLS
COLOR 12
Interface
IntfGSC

DO
kp$ = INKEY$
gscs = 0

IF kp$ = "1" THEN
COLOR 12
LOCATE 7, 19
PRINT "*(1)Search for GS codes*"
Delay 0.3
gscs = gscs + 1
GOTO asearch
END IF

IF kp$ = "2" THEN
COLOR 12
LOCATE 9, 19
PRINT "*(2)Print them all*"
Delay 0.3
gscs = gscs + 1
GOTO oall
END IF

IF kp$ = "9" THEN
SCREEN 12
LOCATE 1, 73
COLOR 15
PRINT "[" + CHR$(19) + "]"
Delay 0.5
COLOR 12
Interface
Menuf
END IF

IF kp$ = "0" THEN
LOCATE 1, 77
COLOR 15
PRINT "[X]"
Delay 0.3
COLOR 12
LOCATE 1, 77
PRINT "[X]"
Exitm
END IF
LOOP

'prints/opens a whole file
oall:
CLS
DO

f$ = ""
IF gscs = 1 THEN
f$ = "GSC.txt"
gscs = 0
GOTO aftr
END IF
IF tut1 = 1 THEN
f$ = "DLET.txt"
tut1 = 0
GOTO aftr
END IF
IF tut2 = 1 THEN
f$ = "DLPT.txt"
tut2 = 0
GOTO aftr
END IF

aftr:
DIM FH AS INTEGER
FH = FREEFILE
OPEN "bathelp.bat" FOR OUTPUT AS #FH
PRINT #FH, "Start /MAX notepad " + CHR$(34) + f$ + CHR$(34)
CLOSE #FH
SHELL "bathelp.bat"


Stopp

GOTO Menu

LOOP

'exit program
ext:
Exitm

SUB Backroundf
COLOR 12
FOR repeat = 1 TO 5
LOCATE 15, 20
PRINT "Loading, Please wait."
Delay 0.3
CLS
LOCATE 15, 20
PRINT "Loading, Please wait.."
Delay 0.3
CLS
LOCATE 15, 20
PRINT "Loading, Please wait..."
Delay 0.3
CLS
Next re
peat
END SUB

SUB Delay (Secs!)

EndTime! = TIMER + Secs!
IF EndTime! > 86400 THEN
     EndTime! = EndTime! - 86400
END IF

DO
LOOP UNTIL TIMER >= EndTime! AND (TIMER - EndTime!) < 1

END SUB

SUB Exitm
COLOR 12
LOCATE 10, 25
PRINT "Shutting Down Prog..."
LOCATE 12, 27
PRINT "Press Any Key"
SLEEP
END
END SUB

SUB Interface
FOR y = 2 TO 79
FOR x = 2 TO 22
LOCATE 1, 1
PRINT CHR$(201)
LOCATE 23, 1
PRINT CHR$(200)
LOCATE 23, 80
PRINT CHR$(188)
LOCATE 1, 80
PRINT CHR$(187)
LOCATE 1, y
PRINT CHR$(205)
LOCATE 23, y
PRINT CHR$(205)
LOCATE x, 80
PRINT CHR$(186)
LOCATE x, 1
PRINT CHR$(186)
LOCATE 1, 73
PRINT "[" + CHR$(19) + "]"
LOCATE 1, 77
PRINT "[X]"
NEXT x
NEXT y
END SUB

SUB IntfGSC
LOCATE 5, 20
PRINT "Would you like to"
COLOR 15
LOCATE 7, 20
PRINT "(1)Search for GS codes"
LOCATE 9, 20
PRINT "(2)Print them all?"
COLOR 12
LOCATE 11, 20
PRINT "(E)xit"
END SUB

SUB Intftut
LOCATE 5, 20
PRINT "Choose a Tutorial"
COLOR 15
LOCATE 7, 20
PRINT "(1)DL's Exit Tutorial"
LOCATE 9, 20
PRINT "(2)DL's Porting Tutorial"
COLOR 12
LOCATE 11, 20
PRINT "(3)Exit"
END SUB

SUB Menuf
COLOR 12
LOCATE 5, 20
PRINT "The Offline Wiki"
LOCATE 7, 20
COLOR 15
PRINT "(1)Search for Actors"
LOCATE 9, 20
PRINT "(2)Tutorials"
LOCATE 11, 20
PRINT "(3)Gameshark Codes"
COLOR 12
LOCATE 15, 20
PRINT "(4)Exit"
END SUB

SUB Stopp
PRINT "Program Paused"
DO
kp$ = INKEY$
IF kp$ <> "" THEN GOTO contin
LOOP
contin:
END SUB

SUB startupm
DIM startup$(12)
startup$(1) =  "A production of Souylsin."
startup$(2) =  " "
startup$(3) =  "Production date: Tuesday, November 27th/07."
startup$(4) =  " "
startup$(5) =  "Thanks to all who contributed to this project."
startup$(6) =  " "
startup$(7) =  "Please make sure all files are in same folder..."
startup$(8) =  " "
startup$(9) =  "TEST COMPLETE"
startup$(10) =  " "
startup$(11) =  " "
startup$(12) =  "Press Any key to Continue"

for x = 1 TO 12
Print startup$(x)
NExt x
END SUB
Mac
Veteran
Posts: 151
Joined: Mon Aug 06, 2007 2:00 pm

More info please

Post by Mac »

Lee wrote:Ok, heres my code now... Im stuck with the command prompt part where is opens a file.
Fix your code so it looks like this:
=======================================================
INPUT "Search for Part of/ file:", sactname$
cmd$ = "FIND /I " + CHR$(34) + sactname$ + CHR$(34) + " " + data$
PRINT "Will execute this command via Shell: "; cmd$
WHILE INKEY$ = "": WEND
SHELL cmd$
=======================================================
OPEN "bathelp.bat" FOR OUTPUT AS #FH
cmd$ = "Start /MAX notepad " + CHR$(34) + f$ + CHR$(34)
PRINT #FH, cmd$
CLOSE #FH
PRINT "Will execute this command in bathelp.bat: "; cmd$
WHILE INKEY$ = "": WEND
SHELL "bathelp.bat"
=======================================================

Then let us know what printed out that subsequently failed.

Mac
Sinuvoid
Veteran
Posts: 155
Joined: Wed Jul 25, 2007 8:20 am

Post by Sinuvoid »

Ok, it had the command that it was going ot put into the command prompt (start /MAX notepad "DLPT.txt") and ti stilled failed. Then when I opened up teh batch file it was perfect :? This is messed up... but thanks anyways!
Mac
Veteran
Posts: 151
Joined: Mon Aug 06, 2007 2:00 pm

Post by Mac »

Lee wrote:This is messed up
Hmm, could you try

Code: Select all

cmd /c start
instead of just Start?

Mac
Post Reply