Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shell command and variables 1

Status
Not open for further replies.

nenebien

Technical User
Sep 11, 2007
2
AR
hello i'm trying to run an external file through shell (C:\>file.exe parameter) and i like let the user to input the parameter in a variable. can i pass the variable to the shell? how?

sorry for my poor english, if i'm not clear please let me know.

thanks!

jul
 
This example passes two parameters to C:\test.bat

QB 4.5 code:

Code:
SHELL "c:\test.bat p1 p2"

test.bat:
Code:
@echo off
cls
echo In TEST.BAT
echo Parameter1 = %1
echo Parameter2 = %2
echo.
pause

Hope this helps.

 
line input "Enter parameter for program ";Var$
shell "C:\File.EXE "+Var$
The space after exe will be mandatory. If it requires
a "/" character then
shell "C:\file.exe /"+Var$
 
EXECUTE THE ".BAT" FILE AS SPECIFIED BY FREESTONE

THEN

In the bat file code

SET MYPARM1=%1
SET MYPARM2=%2



THEN RUN THE PROGRAM WITH THE FOLLOWING CODE AT THE BEGINNING

MYFIRSTPARM$ = ENVIRON$("MYPARM1")
MYSECONDPARM$ = ENVIRON$("MYPARM2")

NOW THE QBASIC PROGRAM CONTAINS THE PASSED STRINGS AS MYFIRSTPARM$ & MYSECONDPARM$ .


Computer thought: I teach a lot of programming so I can learn. You can never learn it all.
 
thank you all!!

I did it with Buff1 advice, thank you all for your interest.

now i've got another issue,

i'm getting "illegal function call" error i guess that's because the commandstring in the SHELL is too big, is there a way to fix that?

thanks again!
 
I doubt that it's too long unless it's over 256 characters.
I would more likely look to an error in the code.

Without at least a snipet though, we are unable to say for
sure. Like saying "I sneezed -- what's wrong with me?"
and expecting the exact diagnosis.
 
Another thought: when you shell to another program/bat file the current environment is passed straight through so the values can be retrieved directly by the shelled program.

you used to be able to increase the set area in the cmd box up to 4k that you run the programs in. look in the system for that possibility, maybe use the properties folder on the cmd icon. Maybe it is in the windows equivalent of autoexec of config files . Sorry I don't have the time right now.

Computer thought: I teach a lot of programming so I can learn. You can never learn it all.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top