Qbasicnews.com
February 25, 2020, 11:56:55 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1] 2 3 4
  Print  
Author Topic: PATH doesn't work within a DOS SHELL --- Why?  (Read 9593 times)
Moneo
Na_th_an
*****
Posts: 1971


« on: February 11, 2004, 05:10:53 PM »

I'm defining a DOS Shell as the state you are in when a program you're running lets you "go to DOS", or you're in Basic and you issue a SHELL command with no operand. You end up on the DOS command line, and when you're done you must type EXIT. This is similar, but not exactly the same, as "going to a DOS prompt or DOS command" from Windows.

I was doing some testing when in a DOS Shell, and found that during my limited testing, almost everything works the same as if you were in a totally DOS machine or if you were at a Windows DOS prompt or command.

What didn't work? I made a batchfile that contained a TYPE, ECHO and a PATH command. The TYPE and ECHO worked fine, but the PATH commmand to  change the current PATH did not work at all. I tried several versions, but it ignores this PATH command inside a batchfile. I tried the PATH command from the command line, and it works fine, changing the PATH. BTW, PATH commands do work from a batchfile on a DOS machine or a Windows DOS prompt.

Ok, does anybody know what's so special about performing a PATH command from inside a batchfile when in a DOS Shell?
*****
Logged
Antoni Gual
Na_th_an
*****
Posts: 1434



WWW
« Reply #1 on: February 11, 2004, 05:23:09 PM »

Remember when you open a SHELL you get a copy of the environment, so what you do there does'nt affect the environment  vars used by qb. When shell closes all your changes are lost
Its the same reason why you can't recover the return value from a program run in a shell.

So the question is how do you check if the path changes were made? You should check from inside the same shell...
Logged

Antoni
TheBigBasicQ
*/-\*
*****
Posts: 4550



WWW
« Reply #2 on: February 12, 2004, 01:43:28 PM »

Urm...if you are trying to change the path just use the CHDIR command. no need to open a shell.
Logged
Moneo
Na_th_an
*****
Posts: 1971


« Reply #3 on: February 12, 2004, 03:24:29 PM »

Quote from: "Antoni Gual"
Remember when you open a SHELL you get a copy of the environment, so what you do there does'nt affect the environment  vars used by qb. When shell closes all your changes are lost
Its the same reason why you can't recover the return value from a program run in a shell.

So the question is how do you check if the path changes were made? You should check from inside the same shell...

Hi Antoni, haven't heard from you in a while.
I think you missed my point. I'll re-phrase the problem:
* I'm in a DOS Shell, and on the command-line.
* If I do a PATH from the command-line IT DOES TAKE EFFECT OK.
* However, if I create a batchfile with a PATH command, and execute the batchfile from the command-line while being in the same DOS Shell, IT IGNORES THIS PATH COMMAND --- WHY?
*****
Logged
TheBigBasicQ
*/-\*
*****
Posts: 4550



WWW
« Reply #4 on: February 12, 2004, 03:29:56 PM »

Moneo, when u launch the batch file, it gets executed in a different shell (i think) so the path is changed but inside the batch file's shell and not the exe which launched it =P.
Logged
Moneo
Na_th_an
*****
Posts: 1971


« Reply #5 on: February 12, 2004, 03:32:30 PM »

Quote from: "TheBigBasicQ"
Urm...if you are trying to change the path just use the CHDIR command. no need to open a shell.

I'm opening a Shell for very specific reasons which I won't get into right now.
A CHDIR or CD command is to change or reposition you onto another directory. It has nothing to do with a PATH command. I use a PATH command to establish paths to common directories that I need most of the time, like \MONEO\BATS, \MONEO\TOOLS and MONEO\QB45, so that at any time I can invoke batchfiles, utilities or the QB45 complier and linker from whatever directory I'm currently at. Get it?
*****
Logged
TheBigBasicQ
*/-\*
*****
Posts: 4550



WWW
« Reply #6 on: February 12, 2004, 03:34:56 PM »

Ah, so u want to change the environment variables of the shell you are currently in. I have no idea how you could achieve it =P.
Logged
Antoni Gual
Na_th_an
*****
Posts: 1434



WWW
« Reply #7 on: February 13, 2004, 05:55:10 AM »

To change your present environment variables you should use ENVIRON$ (or something like this, I don't have QB at hand to check now).
Logged

Antoni
TheBigBasicQ
*/-\*
*****
Posts: 4550



WWW
« Reply #8 on: February 13, 2004, 06:27:00 AM »

way to go. I just checked out ENVIRON$() function and its exactly what Moneo needs.

heres a link =P
Logged
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #9 on: February 13, 2004, 12:42:08 PM »

Moneo, let me undestand this.

1. Let's say you open a shell. For example using QB's "SHELL COMMAND.COM" or in the command line running "COMMAND".

2. Now you run a BAT file that changes the path.

3. Once the BAT has exited, the path is not changed?

Am I right?

Well, I've tried it. If I just open a DOS box and change the path from a BAT file it works. But if I type "COMMAND" to open a new shell it doesn't, for any reason.

I really can't dig a sollution.
Sorry for the useless post Tongue
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
TheBigBasicQ
*/-\*
*****
Posts: 4550



WWW
« Reply #10 on: February 13, 2004, 03:42:49 PM »

Nathan, when he invokes the batch file from inside QB, it opens up a new shell for the batch file. Thus whatever changes he makes to the environment variables through the batch file affects only its own environment and not the .exes =(.

I have posted a link to the Environ$ command which should solve his problem.
Logged
Moneo
Na_th_an
*****
Posts: 1971


« Reply #11 on: February 14, 2004, 02:45:14 PM »

No, I'm running the batchfile from the DOS commandline, the DOS commandline of the DOS Shell that I'm in. I'm not using the QB environment at all.

I think Nathan has discovered something, that is, there seems to be different types of DOS Shells.

I'll look into the ENVIRON stuff though I don't think this has much to do with it.
*****
Logged
Z!re
*/-\*
*****
Posts: 4599


« Reply #12 on: February 14, 2004, 04:12:33 PM »

Path only works for the current DOS shell, as soon as you open a DOS program in a windows shell, it starts a new shell for that program.

Shell1
BAT -> Shell2 (suspend Shell1)
Run BAT using Shell2
BAT -> end (Reactivate Shell1)
Shell1

A BAT file is a new command prompt in itself, you could try:
BAT1:
  SET PATH %PATH, "My path"
  BAT2

And then run BAT1 whenever you want to run BAT2, not sure if this work though.
Logged
Antoni Gual
Na_th_an
*****
Posts: 1434



WWW
« Reply #13 on: February 14, 2004, 09:37:34 PM »

Code:

'When a shell is opened it gets a copy of it's parent's environment
'
'this changes the path in the shell's environment
'
OPEN "chpath.bat" FOR OUTPUT AS 1
PRINT #1, "@echo off"
PRINT #1, "path=a:\"
PRINT #1, "echo path has changed"
PRINT #1, "path"
PRINT #1, "pause"
CLOSE #1
SHELL "chpath.bat"
'
'When a shell is closed it's copy of the environment is deleted
'so in a new shell path is back to the original...
'
OPEN "test.bat" FOR OUTPUT AS 1
PRINT #1, "@echo off"
PRINT #1, "echo and path is..."
PRINT #1, "path"
PRINT #1, "pause"
CLOSE #1
SHELL "test.bat"

'
'this changes path in QB's environment
'
'NOTE: W2000's (probably also XP's) environment is a huge monster
'of 30 lines and QB can't cope with it :ENVIRON gives an out of memory
'error.....It should work in W9x or DOS
'
ENVIRON "path=a:\"
'
'The change in the path is transmitted to the shell
'
SHELL "test.bat"
Logged

Antoni
Moneo
Na_th_an
*****
Posts: 1971


« Reply #14 on: February 15, 2004, 12:07:46 AM »

ANTONI. I know you're trying to help, but your changing the circumstances under which I'm having the problem.

I'll repeat the scenario:

* I'm in a DOS Shell. I get into this shell from a utility program which has an option "go to DOS". I can get the same DOS Shell if I run the old BASIC interpreter and issue a SHELL command with no parameter.

NOTE: I execute the utility program or the BASIC interpreter by selecting and running it from Windows' "My Computer".

The DOS Shell has the following opening message:
<< Use EXIT to return >> Microsoft(R) Windows DOSDn
(C)Copyright Microsoft Corp 1990-2001

* The above puts me on the DOS comand-line. Most everything seems to work when launched from this command-line.

* If I do a PATH from the command-line IT DOES TAKE EFFECT OK.

* However, if I create a batchfile with a PATH command, and execute the batchfile from this command-line while being in the same DOS Shell, IT IGNORES THIS PATH COMMAND --- WHY?

* The same thing happen in Windows 2000 or Windows XP.

NOTE: If I exit to DOS from Windows using the Run CMD, it puts me in a different kind of DOS Shell. If I repeat the above scenario and run the utility program or BASIC to provoke a DOS Shell, then this nested shell won't let me run hardly anything from the comand-line. But, this is not my main concern.
*****
Logged
Pages: [1] 2 3 4
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!