A Windows XP help forum. PCbanter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » PCbanter forum » Microsoft Windows 7 » Windows 7 Forum
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

I need help writing a position independent CMD script



 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old September 19th 17, 07:44 AM posted to alt.windows7.general
mike[_10_]
external usenet poster
 
Posts: 1,073
Default I need help writing a position independent CMD script

I need help writing a position independent CMD script.

I'm helping a friend write a CMD script that is called by
another script in windows 7.

It does a lot of stuff, but the issue is encapsulated by the following...

Directory structure is
D:\
program root directory
dir1
somefiles
dir2
copyscript.bat

The copyscript.bat is one line

xcopy dir1\*.* dir2


The script works fine when executed from program root directory.
But it's called from a script on another partition.
Xcopy can't find dir1 or dir2. It's looking in system32.

The current workaround is to add the following

D:
cd pathto program root directory

That fixes the problem, but it's position dependent.

How do we modify the script so that it runs no matter
where program root directory is? How can the script
determine it's location?

In the current context, it's executed from task scheduler.
Task scheduler allows inputting the working directory.
That's not the question.
Ditto for calling the script thru a shortcut.

I want to learn the path syntax for writing a self-contained
position-independent
CMD script that uses relative addressing in the version of CMD interpreter
that's in win7.
Explanations and links are fine, but the ideal answer would also edit
the above one-line script to make it position independent. The devil is
in the details.

I've already googled my ass off. I'm lost in escape sequences
and parentheses and pre-defined system variables and
the fact that CMD lines may parse differently if they're in a script.
Using a different scripting language won't help. I'd have to learn it
and teach it and become "customer support" forever. That's way beyond
what I'm willing to do.

 




Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off






All times are GMT +1. The time now is 07:25 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 PCbanter.
The comments are property of their posters.