20
3
In shell-scripting if I need to run a command from a directory I can us a subshell to ensure I return to the original context:
(cd temporary/new/directory ; command)
# now I am still in original directory
Can this be done in Windows batch-files (or cmd-files)
Doing the same in batch-files leaves me in the new directory.
I can do:
pushd temporary\new\directory && command && popd
But the popd is dependent on the success of command
.
Any ideas?
How are you invoking your "batch-file" or "cmd-file"? If you put a cd command into a shell script and execute that script (not source it), the current working directory of the calling shell will not change. – garyjohn – 2011-07-29T00:59:52.103
Just to be clear this is referring to windows batch-files. – Greg – 2011-07-30T09:02:28.053
Its a script which runs a bunch of commands in different parts of a directory tree. Some of the commands only operate on the current-directory. Returning to the original directory helps simplify the data that drives the script. Are you suggesting making a separate batch-file for each directory that i need to make calls in? – Greg – 2011-07-30T09:03:52.963
As I recall, you referred to shell scripts and didn't mention Windows in your original question, so I incorrectly assumed that you were using a Unix-like system. Now I understand. – garyjohn – 2011-07-30T15:38:54.320
Yes, sorry, I realise I wasn't clear (although I think 'batch-file' was a hint :-p) – Greg – 2011-08-01T00:20:32.617