Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From   "Gabi Huiber" <ghuiber@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Re: two questions about the shell command behavior -- Windows XP
Date   Mon, 8 Dec 2008 18:27:20 -0500

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 <martin.weiss1@gmx.de> wrote:
> Re backslash see Nick`s
> http://www.stata-journal.com/article.html?article=pr0042
>
> HTH
> Martin
> _______________________
> ----- Original Message ----- From: "Gabi Huiber" <ghuiber@gmail.com>
> To: <statalist@hsphsun2.harvard.edu>
> 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/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index