How to inherit the global path in a new command prompt

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
sambasiva
Posts: 43
Joined: 02 Jun 2013 10:25

How to inherit the global path in a new command prompt

#1 Post by sambasiva » 27 Jan 2015 23:48

Hi,

Could you please help me with the below query.

I have started a command prompt and the PATH (global path) set in it is as below:

Path=C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\
;C:\Program Files\WIDCOMM\Bluetooth Software\;C:\Program Files\WIDCOMM\Bluetooth Software\syswow64;;C:\ACTIVE~1\BIN;C:\Program Files\TortoiseSVN\bin


In this command prompt I reset the PATH to

Path=C:\ProgramData\Oracle\Java\javapath;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;


Then If I start a new command prompt using "cmd.exe /c start" then in the new command prompt it shows the PATH which I re-setted above. Where as I am interested in seeing the global path(which is available before starting the new cmd prompt)
in the new spawned cmd prompt.

Could you please let me know what is the proper way to start a new command prompt to achieve this.


Thanks
Siva

mcnd
Posts: 27
Joined: 08 Jan 2014 07:29

Re: How to inherit the global path in a new command prompt

#2 Post by mcnd » 28 Jan 2015 04:41

Code: Select all

start /i cmd.exe


Where the /i switch instructs start command to use the original environment of the current cmd instance.

sambasiva
Posts: 43
Joined: 02 Jun 2013 10:25

Re: How to inherit the global path in a new command prompt

#3 Post by sambasiva » 28 Jan 2015 07:45

Thanks for your reply.

I have a question further.
Is there a way to start a new cmd window to use the environment from the global environment variables (the ones we see from the mycomputer--->properties).


Thanks
Siva

sambasiva
Posts: 43
Joined: 02 Jun 2013 10:25

Re: How to inherit the global path in a new command prompt

#4 Post by sambasiva » 28 Jan 2015 12:34

Thanks all for your replies.

1) I have a cmd prompt where the below path is set.
Path=C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;

2) In this command prompt I invoke an ant script which installs some new products and set some extra path and perl path
Path=C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;%some_extra_path%;%perl_path%;

3) Later in the same ant program I run a java program which invokes a perl command internally.

Now the issue is, when the java program invokes perl command it says the perl is not found in the path.
But the perl path is set by the ant program which is not visible/inherited to the java program.

I tried to execute the perl using "cmd.exe /c start perl" in the java program, thinking that spawning a new cmd prompt will get the latest path being set (i.e. perl path) but no luck. The path is still showing the old path and I get the perl not found error.


Any pointers to get the perl command executed from the java code properly using the path already set.

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: How to inherit the global path in a new command prompt

#5 Post by Samir » 11 Feb 2015 22:41

This is a little bit beyond batch file programming, but what you are going to have to do is set the path spec for every cmd session. I know there's a place to do that in xp under control panel-->system. Good luck.

Post Reply