#122468 - 2004-07-09 02:36 PM
Hide output of shell "%Comspec% /c rd /s /q..." ?
|
Learic
Fresh Scripter
Registered: 2004-02-16
Posts: 12
|
Frist off, I need to say that I know Kix offers the "RD" command to remove directories but it has to be empty. This is the main reason I have to use the Shell command to invoke the windows version of "RD" that will remove all files, subdirs, and the directory itself! Here's the code I have a question about.
RedirectOutput("NUL") Shell "%comspec% /c rd /s /q $Directory" RedirectOutput("CON")
$Driectory is actually a directory name in my code such as "C:\yadayadayada"
When I invoke this script, I get "The system cannot find the file specified." This is normal if the directory I'm deleting doesn't exist. I was wondering if there is a way to HIDE any output given from a command that is invoked with SHELL. Here's the reasoning..
It is possible for a directory to have a file existing which means the directory is still needed by the system because the executable is running as a service. If the specific file I'm looking for does not exist however and the directory is still there, I need to delete it and anything else that is contained within it. I'm basically trying to clean up an installed program that doesn't clean up well on it's own. The uninstall will always delete the main file that runs as a service but it is possible for it to leave a directory behind with other non-necessary files still intact. So here is the code I'm trying.
IF NOT EXIST("$Directory\Executable.exe") RedirectOutput("NUL") Shell "%comspec% /c rd /s /q $Directory" RedirectOutput("CON") Else $Directory_Delete=FAILED ENDIF
|
|
Top
|
|
|
|
#122474 - 2004-07-09 02:57 PM
Re: Hide output of shell "%Comspec% /c rd /s /q..." ?
|
Learic
Fresh Scripter
Registered: 2004-02-16
Posts: 12
|
Thanks Shawn! That worked.. I tried the >NUL originally but removed it since it wasn't working! Didn't know that I could do >NUL 2>NUL and that works beautifully!
|
|
Top
|
|
|
|
#122480 - 2004-07-09 03:49 PM
Re: Hide output of shell "%Comspec% /c rd /s /q..." ?
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Quote:
Your welcome. No one ever wants to debate me on this, but if $vars in strings are evil, than %vars%'s in strings are equally evil.
We did have a rambling debate on this, but I can't find it. I'd agree that "no vars" should include anything that might be expanded, including macros and environment strings.
I did turn up a quote from Ruud stating that he intended to have a NoMacrosInStrings.
Quote:
should HKCU and HKLM also be excluded cuz they too are macros of sorts.
Not really. They don't get expanded at all - HKCU is just HKCU regardless of how or where you use it. The only thing that is special about it is that if it is at the start of a string passed to a registry function it is recognised by the function as a shorthand or alias. The string that the function receives however remains unchanged.
|
|
Top
|
|
|
|
#122481 - 2004-07-09 03:57 PM
Re: Hide output of shell "%Comspec% /c rd /s /q..." ?
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
imho they're different, they're not vars. I'm not saying I'm necessarily right or wrong on this point. Just wanted to point-out some inconsistencies in the "rules" and get some opinion. I posed this @macro/%var% question to Ruud ages ago when he first came out with NoVarsInStrings ... and he didn't bite. To be honest, think (he thinks) its a bit of a rat hole to go down.
The question is, is there really a fundamental difference between this:
$x = "$windir\system32"
and this:
$x = "%windir%\system32"
and if not, then should "best practice" be:
$x = %windir% + "\system32"
I myself don't get too worried about vars-in-strings - our corp login script (even the newest one we just did) are riddled with them. Were we (I) concerned about $vars being not supported in the future ? Sure was - but I truely think Ruud will never "go there" ... thoughts ?
By the way, the HKLM / HKCU thingy is different because if they were expressed outside of quotes, it would break another "rule". It would be an un-quoted string (which some have been quilty of doing too :0) )
$key = HKCU + "\Control Panel"
funny enough though, that syntax still works 
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 1257 anonymous users online.
|
|
|