DOS bat file to add to path

 
Thread Tools Search this Thread
Special Forums Windows & DOS: Issues & Discussions DOS bat file to add to path
# 1  
Old 08-26-2013
DOS bat file to add to path

This may not be the right place, since it is not exactly unix or linux, but it does involve cygwin. I have two cygwin installations. When I start a mintty terminal, I need to toggle a windows path variable to make sure that the correct cygwin dll gets loaded.

I need to add
Code:
C:\cygwin\bin

to the windows path for one of the installs. I can make a bat file with,

Code:
SET PATH = C:\cygwin\bin;%PATH%;

as far as I know, this will add the right string to the path. The issue is that I need this to be temporary for the session only. I am not sure how to do this. I may be able to use "setlocal", but when the bat file finishes, it will close and I'm guessing that the temp assignment to the path will go with it. This means that I would need to have the bat file stay open until I close it intentionally when I am done. It would be more useful to have the path addition stay put until I close the mintty terminal, but I'm not sure how to do that. I suppose I could have a bat file that would add cygwin to the path and then another one that would remove it, but it seems like there should be a better way than that. I guess I could also just open a cmd terminal and add cygwin to the path there and remove it when I was done.

I would like to just have a desktop shortcut that would add cygwin to the path, open a mintty terminal, and then when I am done, restore the path to it's original value. It doesn't seem as if that should be that difficult, but I'm not making much progress with google.

Let me know if this just isn't the right place and I will look elsewhere.

LMHmedchem

Last edited by Scrutinizer; 08-26-2013 at 04:08 AM.. Reason: code tags
# 2  
Old 08-26-2013
You could have the batch file run the terminal, inherit those environment changes.
# 3  
Old 08-27-2013
Thanks for the reply.

This seems to work,
Code:
@echo off
SET PATH = C:\cygwin\bin;%PATH%;
start "" /b C:\cygwin\bin\mintty.exe -i /Cygwin-Terminal.ico -

Apparently the /b flag opens the program in the same console. I guess that means that mintty inherits the change. If I run this bat and enter "echo $PATH" in the terminal I get,

/usr/local/bin:/usr/bin:/cygdrive/c/Program Files/Intel/iCLS Client:/cygdrive/c/WINDOWS/system32:/cygdrive/c/WINDOWS:/cygdrive/c/WINDOWS/System32/Wbem:/cygdrive/c/Program Files/Intel/Intel(R) Management Engine Components/DAL:/cygdrive/c/Program Files/Intel/Intel(R) Management Engine Components/IPT:/cygdrive/c/Program Files/Emergent 5.3.9 (32-bit)/bin:/usr/lib/lapack

It appears as if the cygwin directories are in the path ( /usr/local/bin:/usr/bin: ). I have no real way of knowing if the is the correct /usr/local/bin since cygwin has truncated the path names.

The problem is that if I start a terminal from the normal shortcut (not using the bat file above) I get the same information when I echo $PATH. I also don't know if I need to start every terminal and every program from such a bat file.

I think it might make more sense to have the cygwin1 install location always be in the path as an environment variable since that is the one I use most often. If I need the cygwin2 install, I would need to run a bat file that would remove the cygwin1 install location from that path and then insert the cygwin2 install location for that session only.

Does that make sense???

LMHmedchem
# 4  
Old 08-27-2013
Quote:
Originally Posted by LMHmedchem
I may be able to use "setlocal", but when the bat file finishes, it will close and I'm guessing that the temp assignment to the path will go with it. This means that I would need to have the bat file stay open until I close it intentionally when I am done.
As it is: no. Unix shells work like that, but DOS doesn't. In fact, when you set a variable in a DOS batch file its value stays until you start the COMMAND.COM (or whatever replacement you use) anew. This is the reason why you can set the PATH variable in AUTOEXEC.BAT and have that change be persistent.

I hope this helps.

bakunin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How do I add a log file path to a vi file to monitor all the changes made to the file?

I'm curious to know how do I add an empty log file (test1.log) to an existing text file to monitor all the changes made to a.txt. Is this expression export PATH=$PATH:/home/test1.log right to be added to the text file a.txt? (5 Replies)
Discussion started by: TestKing
5 Replies

2. Windows & DOS: Issues & Discussions

Avoiding DOS space related "path not found errors"

Well I have a lot of scripts that require dragging and dropping files in order to define Source files etc. However more often then not it is the case that the path to said file contains NUMEROUS spaces. I know one way to evade this problem is to encase the path in Quotes like this: ... (7 Replies)
Discussion started by: pasc
7 Replies

3. Shell Programming and Scripting

Need help with bat file!!!

I need to put/get files from Windows machine to Unix machine and vice-versa. I wrote a text file "ftp1.txt" as below. naga naga06 cd /root/Naga prom off get time.unl bye I wrote another bat file "ftp.bat" as below. ftp -n -s:C:\Users\Naga\Desktop\ftp1.txt IP_ADDRESS but... (2 Replies)
Discussion started by: Naga06
2 Replies

4. Solaris

cannot add PATH to user crontab file

hi All, here is the problem: I'm not able to specify a PATH inside the user crontab file (/var/spool/cron/crontabs). The only syntax it accepts is the usual "* * * * * file" I'm not able to add PATH, or HOME, or MAILTO, or anything else. when I try to save the crontab, I have the error: ... (1 Reply)
Discussion started by: joe_x
1 Replies

5. Shell Programming and Scripting

Building a DOS .bat file that will root my Droid 2 phone using adb

1. What I am doing? Building a DOS .bat file that will root my Droid 2 phone using adb commands in the .bat file. (Just for the fun of it and to help me learn "stuff".) 2. Problem: Here are the problem steps to accomplish this task manually in an adb shell: adb shell (Prompt is $) cd... (2 Replies)
Discussion started by: chrstdvd
2 Replies

6. Windows & DOS: Issues & Discussions

DOS Dir - listing of full path and timestamp

Hi, (Apologies, I'm sure I'm not the first person to raise this question but so far in my searches haven't found a good answer). I would like to output a listing per line of filename (including full path) and 'last updated' timestamp. e.g: Z:\dir1\file1.txt 01/02/2010 10:43... (5 Replies)
Discussion started by: GM_AIX
5 Replies

7. Shell Programming and Scripting

Simple bat file

Hi guys, I need a *.bat to run a ksh file in the shell on Windows NT...nothing more :) How do I do it? I tried with the following but it failed: set INFORMIXDIR=D:\user-applications\informix set PATH=%INFORMIXDIR%;%PATH% D:\user-applications\MKS\mksnt\sh.exe C:\hk_9.2\C3_weekly_auto.ksh... (4 Replies)
Discussion started by: Dird
4 Replies

8. Linux

dos-path / un-dos-path compatibility with cygwin

Hello ; I have a problem running some script on dos . when i run : C: ls /temp ls: cannot access /temp: No such file or directory but when i run C: ls \temp windriver backup remotebackup also when i run C: ls temp windriver backup remotebackup The... (4 Replies)
Discussion started by: mulder20
4 Replies

9. Windows & DOS: Issues & Discussions

compatibility cygwin / with dos-path

when i run in dos for example: C: ls /temp ls: cannot access /temp: No such file or directory but when i run C: ls \temp windriver backup remotebackup also when i run C: ls temp windriver backup remotebackup The problems that i have all developpers scripts was written first like this... (0 Replies)
Discussion started by: mulder20
0 Replies

10. UNIX for Dummies Questions & Answers

Can Unix (Solaris) execute a dos .bat script?

I did a search and found lots of questions/comments about how a dos script could execute Unix but not the other way round. If it's possible, I'd like the link to a post/site that would show me the way. Thanks. (4 Replies)
Discussion started by: BCarlson
4 Replies
Login or Register to Ask a Question