st: two questions about the shell command behavior -- Windows XP

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

st: two questions about the shell command behavior -- Windows XP

Gabi Huiber
Hello everybody,

I need to make room on a disk and I thought I'd do this on an ongoing
basis from within a larger Stata process that runs every day. So I
need to move files around. I thought that this prototype would get me
started:

clear
set more off

local root      "c:/work/my root directory/"
local to_path   "to_here\"
local from_path "from_here\"
local move_this "example_list.txt"

cd "`root'"

!move `from_path'`move_this' `to_path'`move_this'
dir "`to_path'"
dir "`from_path'"

!move `from_path'example_list.txt `to_path'example_list.txt
dir "`to_path'"
dir "`from_path'"

I have two questions about the shell command:

1. The shell modifier (shell or !) seems to pass along the local
macros with the immediate folder names -- `from_path' and `to_path' --
but it does not do the same with the local macro that holds the file
name. It would be nice if it did, because local macros that hold file
names would make it a lot easier to loop across multiple file name
variants. Does anybody know what explains this selective treatment of
local macros?

2. The shell modifier does not allow me to enclose file path or file
name macros in quotes in order to accommodate spaces. In this case I
cd'd into the `root' path and the very last folders of interest had no
spaces, but I won't always be so lucky. Does anybody know of a
workaround?

3. This is more an idle puzzle than a real issue, though it might grow
into one. When I started using forward slashes in Stata, I thought I
could do so because Windows didn't care either way. But it does. The
XP command prompt does not recognize forward slashes. So it's very
nice of Stata to make that problem go away, especially if you have
folder names whose first character, when paired with a backslash,
could be mistaken for a special character. I guess, though, that Stata
can only go so far in offering this convenience. You have to
relinquish it when you invoke the shell, it seems. Too bad, but not
critical.

But issues (1) and (2) are nuisances, and they are strange. Inside
Stata you can string along as many macros as you want, so (1) should
not be an problem; and you can use quotes to declare file paths with
spaces in them both inside Stata and at the Windows command prompt, so
(2) shouldn't be one either.

Thank you,

Gabi
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|

st: Re: two questions about the shell command behavior -- Windows XP

Martin Weiss-5
Re backslash see Nick`s
http://www.stata-journal.com/article.html?article=pr0042

HTH
Martin
_______________________
----- Original Message -----
From: "Gabi Huiber" <[hidden email]>
To: <[hidden email]>
Sent: Monday, December 08, 2008 10:51 PM
Subject: st: two questions about the shell command behavior -- Windows XP


> Hello everybody,
>
> I need to make room on a disk and I thought I'd do this on an ongoing
> basis from within a larger Stata process that runs every day. So I
> need to move files around. I thought that this prototype would get me
> started:
>
> clear
> set more off
>
> local root      "c:/work/my root directory/"
> local to_path   "to_here\"
> local from_path "from_here\"
> local move_this "example_list.txt"
>
> cd "`root'"
>
> !move `from_path'`move_this' `to_path'`move_this'
> dir "`to_path'"
> dir "`from_path'"
>
> !move `from_path'example_list.txt `to_path'example_list.txt
> dir "`to_path'"
> dir "`from_path'"
>
> I have two questions about the shell command:
>
> 1. The shell modifier (shell or !) seems to pass along the local
> macros with the immediate folder names -- `from_path' and `to_path' --
> but it does not do the same with the local macro that holds the file
> name. It would be nice if it did, because local macros that hold file
> names would make it a lot easier to loop across multiple file name
> variants. Does anybody know what explains this selective treatment of
> local macros?
>
> 2. The shell modifier does not allow me to enclose file path or file
> name macros in quotes in order to accommodate spaces. In this case I
> cd'd into the `root' path and the very last folders of interest had no
> spaces, but I won't always be so lucky. Does anybody know of a
> workaround?
>
> 3. This is more an idle puzzle than a real issue, though it might grow
> into one. When I started using forward slashes in Stata, I thought I
> could do so because Windows didn't care either way. But it does. The
> XP command prompt does not recognize forward slashes. So it's very
> nice of Stata to make that problem go away, especially if you have
> folder names whose first character, when paired with a backslash,
> could be mistaken for a special character. I guess, though, that Stata
> can only go so far in offering this convenience. You have to
> relinquish it when you invoke the shell, it seems. Too bad, but not
> critical.
>
> But issues (1) and (2) are nuisances, and they are strange. Inside
> Stata you can string along as many macros as you want, so (1) should
> not be an problem; and you can use quotes to declare file paths with
> spaces in them both inside Stata and at the Windows command prompt, so
> (2) shouldn't be one either.
>
> Thank you,
>
> Gabi
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|

st: RE: two questions about the shell command behavior -- Windows XP

Nick Cox
In reply to this post by Gabi Huiber
I've got only partial comments. I don't understand your #1.

1. The shell never sees local macros, only their contents
=========================================================

You have got to think in terms of what you type and what the shell sees
as related, but quite distinct.

In particular, the shell knows nothing about local macros. It only sees
what the interpreter (for so we'll dub the part of Stata that takes what
you type and tries to make sense of it) passes along.

So, when you write about passing along local macros, that is at best
shorthand for the results: i.e. it is as if the local macros are passed
because the shell gets to see their contents.

My guess is that your understanding is better than your writing, but I
have only your writing to judge.

2. Windows doesn't know about Stata's flexibility -- or otherwise
=================================================================

I think you're right. Windows knows nothing about Stata's willingness to
indulge \ and / alike -- or about Stata's insistence on " " to
disambiguate filepaths with spaces.

Nick
[hidden email]

Gabi Huiber

I need to make room on a disk and I thought I'd do this on an ongoing
basis from within a larger Stata process that runs every day. So I
need to move files around. I thought that this prototype would get me
started:

clear
set more off

local root      "c:/work/my root directory/"
local to_path   "to_here\"
local from_path "from_here\"
local move_this "example_list.txt"

cd "`root'"

!move `from_path'`move_this' `to_path'`move_this'
dir "`to_path'"
dir "`from_path'"

!move `from_path'example_list.txt `to_path'example_list.txt
dir "`to_path'"
dir "`from_path'"

I have two questions about the shell command:

1. The shell modifier (shell or !) seems to pass along the local
macros with the immediate folder names -- `from_path' and `to_path' --
but it does not do the same with the local macro that holds the file
name. It would be nice if it did, because local macros that hold file
names would make it a lot easier to loop across multiple file name
variants. Does anybody know what explains this selective treatment of
local macros?

2. The shell modifier does not allow me to enclose file path or file
name macros in quotes in order to accommodate spaces. In this case I
cd'd into the `root' path and the very last folders of interest had no
spaces, but I won't always be so lucky. Does anybody know of a
workaround?

3. This is more an idle puzzle than a real issue, though it might grow
into one. When I started using forward slashes in Stata, I thought I
could do so because Windows didn't care either way. But it does. The
XP command prompt does not recognize forward slashes. So it's very
nice of Stata to make that problem go away, especially if you have
folder names whose first character, when paired with a backslash,
could be mistaken for a special character. I guess, though, that Stata
can only go so far in offering this convenience. You have to
relinquish it when you invoke the shell, it seems. Too bad, but not
critical.

But issues (1) and (2) are nuisances, and they are strange. Inside
Stata you can string along as many macros as you want, so (1) should
not be an problem; and you can use quotes to declare file paths with
spaces in them both inside Stata and at the Windows command prompt, so
(2) shouldn't be one either.


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|

st: RE: two questions about the shell command behavior -- Windows XP

Kieran McCaul
In reply to this post by Gabi Huiber
I've removed the underscores in the to and from paths and also from the
file name.
I think this works.
Note the double slashes at the end of the to_path and from_path macros
and the space after `move_this' in the -move- line.

clear
set more off

local root      "c:/work/my root directory/"
local to_path   "to here\\"
local from_path "from here\\"
local move_this "example list.txt"

cd "`root'"

!move "`from_path'`move_this' " "`to_path'`move_this'"
dir "`from_path'"
dir "`to_path'"



______________________________________________
Kieran McCaul MPH PhD
WA Centre for Health & Ageing (M573)
University of Western Australia
Level 6, Ainslie House
48 Murray St
Perth 6000
Phone: (08) 9224-2140
Fax: (08) 9224 8009
email: [hidden email]
http://myprofile.cos.com/mccaul 
_______________________________________________
The fact that no one understands you doesn't make you an artist.

-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Gabi Huiber
Sent: Tuesday, 9 December 2008 6:52 AM
To: [hidden email]
Subject: st: two questions about the shell command behavior -- Windows
XP

Hello everybody,

I need to make room on a disk and I thought I'd do this on an ongoing
basis from within a larger Stata process that runs every day. So I
need to move files around. I thought that this prototype would get me
started:

clear
set more off

local root      "c:/work/my root directory/"
local to_path   "to_here\"
local from_path "from_here\"
local move_this "example_list.txt"

cd "`root'"

!move `from_path'`move_this' `to_path'`move_this'
dir "`to_path'"
dir "`from_path'"

!move `from_path'example_list.txt `to_path'example_list.txt
dir "`to_path'"
dir "`from_path'"

I have two questions about the shell command:

1. The shell modifier (shell or !) seems to pass along the local
macros with the immediate folder names -- `from_path' and `to_path' --
but it does not do the same with the local macro that holds the file
name. It would be nice if it did, because local macros that hold file
names would make it a lot easier to loop across multiple file name
variants. Does anybody know what explains this selective treatment of
local macros?

2. The shell modifier does not allow me to enclose file path or file
name macros in quotes in order to accommodate spaces. In this case I
cd'd into the `root' path and the very last folders of interest had no
spaces, but I won't always be so lucky. Does anybody know of a
workaround?

3. This is more an idle puzzle than a real issue, though it might grow
into one. When I started using forward slashes in Stata, I thought I
could do so because Windows didn't care either way. But it does. The
XP command prompt does not recognize forward slashes. So it's very
nice of Stata to make that problem go away, especially if you have
folder names whose first character, when paired with a backslash,
could be mistaken for a special character. I guess, though, that Stata
can only go so far in offering this convenience. You have to
relinquish it when you invoke the shell, it seems. Too bad, but not
critical.

But issues (1) and (2) are nuisances, and they are strange. Inside
Stata you can string along as many macros as you want, so (1) should
not be an problem; and you can use quotes to declare file paths with
spaces in them both inside Stata and at the Windows command prompt, so
(2) shouldn't be one either.

Thank you,

Gabi
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|

Re: st: Re: two questions about the shell command behavior -- Windows XP

Gabi Huiber
In reply to this post by Martin Weiss-5
Nick and Martin, thank you.

Nick's advice to just use forward slashes, in the last paragraph of
the article that Martin referenced, is actually older. I'm not sure
how old, but I'm sure it's from him that I heard it first. I've been
both heeding it and passing it along to others for a couple of years
now at least. That's not the issue.

The issue is this: assuming that you use Windows XP (no idea how other
operating systems would behave) try and have Stata do the do-file that
I embedded in my first message. You can pick a file on your own
computer, declare its home folder as `from_path' and the folder you
want it to go to as `to_path' and give it a try. You will see that the
first !move has no consequences: dir will show that the `move_this'
file is still in the `from_path' folder.

This, I reasoned, was evidence that Windows did not receive the
content of either the first macro -- `from_path' -- or that of the
second -- `move_this' -- or neither. So I tried another variant, where
the file path was declared as a macro, and the file name was instead
spelled out. That one worked. So Stata passes along to the Windows
shell the content of the file path macro in both instances -- both
`from_path' and `to_path' -- but not the content of the file name
macro.

That is strange because, as everyone expects, inside Stata you can
string along as many macros as you want -- either by concatenating
them or by nesting them. That's the gist of (1): I have no idea why
the content of one local macro is passed along to the shell as
expected, while the other is lost.

Thanks again,

Gabi


On Mon, Dec 8, 2008 at 4:56 PM, Martin Weiss <[hidden email]> wrote:

> Re backslash see Nick`s
> http://www.stata-journal.com/article.html?article=pr0042
>
> HTH
> Martin
> _______________________
> ----- Original Message ----- From: "Gabi Huiber" <[hidden email]>
> To: <[hidden email]>
> Sent: Monday, December 08, 2008 10:51 PM
> Subject: st: two questions about the shell command behavior -- Windows XP
>
>
>> Hello everybody,
>>
>> I need to make room on a disk and I thought I'd do this on an ongoing
>> basis from within a larger Stata process that runs every day. So I
>> need to move files around. I thought that this prototype would get me
>> started:
>>
>> clear
>> set more off
>>
>> local root      "c:/work/my root directory/"
>> local to_path   "to_here\"
>> local from_path "from_here\"
>> local move_this "example_list.txt"
>>
>> cd "`root'"
>>
>> !move `from_path'`move_this' `to_path'`move_this'
>> dir "`to_path'"
>> dir "`from_path'"
>>
>> !move `from_path'example_list.txt `to_path'example_list.txt
>> dir "`to_path'"
>> dir "`from_path'"
>>
>> I have two questions about the shell command:
>>
>> 1. The shell modifier (shell or !) seems to pass along the local
>> macros with the immediate folder names -- `from_path' and `to_path' --
>> but it does not do the same with the local macro that holds the file
>> name. It would be nice if it did, because local macros that hold file
>> names would make it a lot easier to loop across multiple file name
>> variants. Does anybody know what explains this selective treatment of
>> local macros?
>>
>> 2. The shell modifier does not allow me to enclose file path or file
>> name macros in quotes in order to accommodate spaces. In this case I
>> cd'd into the `root' path and the very last folders of interest had no
>> spaces, but I won't always be so lucky. Does anybody know of a
>> workaround?
>>
>> 3. This is more an idle puzzle than a real issue, though it might grow
>> into one. When I started using forward slashes in Stata, I thought I
>> could do so because Windows didn't care either way. But it does. The
>> XP command prompt does not recognize forward slashes. So it's very
>> nice of Stata to make that problem go away, especially if you have
>> folder names whose first character, when paired with a backslash,
>> could be mistaken for a special character. I guess, though, that Stata
>> can only go so far in offering this convenience. You have to
>> relinquish it when you invoke the shell, it seems. Too bad, but not
>> critical.
>>
>> But issues (1) and (2) are nuisances, and they are strange. Inside
>> Stata you can string along as many macros as you want, so (1) should
>> not be an problem; and you can use quotes to declare file paths with
>> spaces in them both inside Stata and at the Windows command prompt, so
>> (2) shouldn't be one either.
>>
>> Thank you,
>>
>> Gabi
>> *
>> *   For searches and help try:
>> *   http://www.stata.com/help.cgi?search
>> *   http://www.stata.com/support/statalist/faq
>> *   http://www.ats.ucla.edu/stat/stata/
>>
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|

Re: st: RE: two questions about the shell command behavior -- Windows XP

Gabi Huiber
In reply to this post by Kieran McCaul
That's it. Thank you, Kieran.

I'm sure that the culprit is not the underscore. The double backslash
must have done the job. You need to 'escape the escape' as it were.

Gabi

On Mon, Dec 8, 2008 at 6:05 PM, Kieran McCaul
<[hidden email]> wrote:

> I've removed the underscores in the to and from paths and also from the
> file name.
> I think this works.
> Note the double slashes at the end of the to_path and from_path macros
> and the space after `move_this' in the -move- line.
>
> clear
> set more off
>
> local root      "c:/work/my root directory/"
> local to_path   "to here\\"
> local from_path "from here\\"
> local move_this "example list.txt"
>
> cd "`root'"
>
> !move "`from_path'`move_this' " "`to_path'`move_this'"
> dir "`from_path'"
> dir "`to_path'"
>
>
>
> ______________________________________________
> Kieran McCaul MPH PhD
> WA Centre for Health & Ageing (M573)
> University of Western Australia
> Level 6, Ainslie House
> 48 Murray St
> Perth 6000
> Phone: (08) 9224-2140
> Fax: (08) 9224 8009
> email: [hidden email]
> http://myprofile.cos.com/mccaul
> _______________________________________________
> The fact that no one understands you doesn't make you an artist.
>
> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of Gabi Huiber
> Sent: Tuesday, 9 December 2008 6:52 AM
> To: [hidden email]
> Subject: st: two questions about the shell command behavior -- Windows
> XP
>
> Hello everybody,
>
> I need to make room on a disk and I thought I'd do this on an ongoing
> basis from within a larger Stata process that runs every day. So I
> need to move files around. I thought that this prototype would get me
> started:
>
> clear
> set more off
>
> local root      "c:/work/my root directory/"
> local to_path   "to_here\"
> local from_path "from_here\"
> local move_this "example_list.txt"
>
> cd "`root'"
>
> !move `from_path'`move_this' `to_path'`move_this'
> dir "`to_path'"
> dir "`from_path'"
>
> !move `from_path'example_list.txt `to_path'example_list.txt
> dir "`to_path'"
> dir "`from_path'"
>
> I have two questions about the shell command:
>
> 1. The shell modifier (shell or !) seems to pass along the local
> macros with the immediate folder names -- `from_path' and `to_path' --
> but it does not do the same with the local macro that holds the file
> name. It would be nice if it did, because local macros that hold file
> names would make it a lot easier to loop across multiple file name
> variants. Does anybody know what explains this selective treatment of
> local macros?
>
> 2. The shell modifier does not allow me to enclose file path or file
> name macros in quotes in order to accommodate spaces. In this case I
> cd'd into the `root' path and the very last folders of interest had no
> spaces, but I won't always be so lucky. Does anybody know of a
> workaround?
>
> 3. This is more an idle puzzle than a real issue, though it might grow
> into one. When I started using forward slashes in Stata, I thought I
> could do so because Windows didn't care either way. But it does. The
> XP command prompt does not recognize forward slashes. So it's very
> nice of Stata to make that problem go away, especially if you have
> folder names whose first character, when paired with a backslash,
> could be mistaken for a special character. I guess, though, that Stata
> can only go so far in offering this convenience. You have to
> relinquish it when you invoke the shell, it seems. Too bad, but not
> critical.
>
> But issues (1) and (2) are nuisances, and they are strange. Inside
> Stata you can string along as many macros as you want, so (1) should
> not be an problem; and you can use quotes to declare file paths with
> spaces in them both inside Stata and at the Windows command prompt, so
> (2) shouldn't be one either.
>
> Thank you,
>
> Gabi
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/