Page 1 of 2 12>
Topic Options
#102618 - 2003-07-08 12:32 AM Shell and quotes
kholm Offline
Korg Regular
*****

Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
Shell and quotes

I need to know more [Eek!]

Any commandline freaks out there ?

Win2k+ Shell treats quotes in a different way than the previous M$ OS's

This is a valid Shell execution in Win9x + WinNT:
Shell '%COMSPEC% /C "\\Server\Share\Oracle install\setup.exe" -responseFile "\\Server\Share\Oracle Install\Clientappuser.rsp" -nowelcome'

In Win2k+ Only one pair of quotes is allowed on the commandline by default

So how do i pass this to a Shell;
Shell '"Path\Program" -Arg1 "Path\ParameterFile" -Arg2'

Where both:
"Path\Program"
And
"Path\ParameterFile"
Contains spaces

-Erik

Top
#102619 - 2003-07-08 12:44 AM Re: Shell and quotes
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
I've never seen any documentation stating it will only allow one set of quotes... and I'm sure at some point I have done the very thing you are doing... if you have documentation of the double quote thing I would be interested in reading it...

I'm going to try something and will post back in a few minutes...

Top
#102620 - 2003-07-08 12:47 AM Re: Shell and quotes
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
If you do not use the "/C" switch then you can use two sets of quotes.

code:
Break On
Shell '"c:\data\N F\kix32.exe" "c:\data\N F\junk.kix"'

c:\data\N F\junk.kix
code:
Break On
$dir=join(split(@DATE,"/"),".") + "_" + join(split(@TIME,":"),".")
? $dir

From CMD /?:
code:
If /C or /K is specified, then the remainder of the command line after
the switch is processed as a command line, where the following logic is
used to process quote (") characters:

1. If all of the following conditions are met, then quote characters
on the command line are preserved:

- no /S switch
- exactly two quote characters
- no special characters between the two quote characters,
where special is one of: &<>()@^|
- there are one or more whitespace characters between the
the two quote characters
- the string between the two quote characters is the name
of an executable file.

2. Otherwise, old behavior is to see if the first character is
a quote character and if so, strip the leading character and
remove the last quote character on the command line, preserving
any text after the last quote character.



[ 08. July 2003, 00:49: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#102621 - 2003-07-08 01:20 AM Re: Shell and quotes
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
That reads like stereo instructions ...
Top
#102622 - 2003-07-08 01:29 AM Re: Shell and quotes
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
This is interesting...

I've done numerous bat files that contained two sets of quotes, and not once did I ever have any problems. However, I cannot say I ever used two sets of quotes AND two sets of parameters in the same command...

I can't think of a single test that I can use to duplicate what you are trying. I did try the following but it only contains one parameter, so while this does work, its not the same thing...

code:
break on
shell '%comspec% /c xcopy "c:\test 1\table.htm" "c:\test 2\" /a'
? @serror
? @error

Just out of curiousity, have you tried the command in the dos shell to see what kind of error it gives you.

Top
#102623 - 2003-07-08 01:35 AM Re: Shell and quotes
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
I was trying this cmdline:

SHELL '%COMSPEC% /c "%SYSTEMROOT%\SYSTEM32\NOTEPAD.EXE" "%TEMP%\TEXT.TXT" '

Doesn't work, it cant read the filename, but if you copy&paste into the console, it works ...

-Shawn

[ 08. July 2003, 01:35: Message edited by: Shawn ]

Top
#102624 - 2003-07-08 02:02 AM Re: Shell and quotes
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
While I would never recommend doing this, I have seen a "Working" batch file that contained quotes only around the directories that had spaces... the first time I saw it I was sure this could not work, but in fact it did...using your example...

code:
  Shell '%COMSPEC% /C \\Server\Share\"Oracle install"\setup.exe -responseFile \\Server\Share\"Oracle Install"\Clientappuser.rsp -nowelcome'

Who knows... it might work? [Razz]

Top
#102625 - 2003-07-08 02:02 AM Re: Shell and quotes
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Shawn, is your DOS window COMMAND.COM or CMD.EXE?
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#102626 - 2003-07-08 02:06 AM Re: Shell and quotes
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
quote:
c:\data\scripts>%COMSPEC% /c "%SYSTEMROOT%\SYSTEM32\NOTEPAD.EXE" "%TEMP%\TEXT.TXT"
The filename, directory name, or volume label syntax is incorrect.

_________________________
Home page: http://www.kixhelp.com/hb/

Top
#102627 - 2003-07-08 02:06 AM Re: Shell and quotes
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Howard, command window is cmd.exe

[edit]

I meant that i just copy/pasted the stuff starting in quotes, not the entire shell command (not including the %COMSPEC% /C)

[ 08. July 2003, 02:08: Message edited by: Shawn ]

Top
#102628 - 2003-07-08 02:13 AM Re: Shell and quotes
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Well the SHELL command is calling %comspec%

code:
c:\data\scripts>C:\WINNT\system32\cmd.exe /c "%SYSTEMROOT%\SYSTEM32\NOTEPAD.EXE" "%TEMP%\TEXT.TXT"
The filename, directory name, or volume label syntax is incorrect.

This is what the kixtart script is seeing.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#102629 - 2003-07-08 02:27 AM Re: Shell and quotes
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
I always kinda figured that %COMSPEC% and the dos console were kinda the same thing. But this does seems to work though ... been playing a bit ...

SHELL '%COMSPEC% /C ""%USERPROFILE%\DESKTOP\NOTEPAD.EXE" "%USERPROFILE%\TEXT.TXT" '

Both those paths (on xp) are long filenames with spaces. Notice the double quotes - is this crazy ?

-Shawn

[ 08. July 2003, 02:27: Message edited by: Shawn ]

Top
#102630 - 2003-07-08 02:47 AM Re: Shell and quotes
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
That works on W2K - it is crazy!! [Eek!]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#102631 - 2003-07-08 02:52 AM Re: Shell and quotes
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
I think that

SHELL '%COMSPEC% /C ""%USERPROFILE%\DESKTOP\NOTEPAD.EXE" "%TMP%\LOGON.LOG"" '

is more correct because the rules posted above state that the first and last quote will be stripped and the remaining text will be passed as the command string.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#102632 - 2003-07-08 03:22 AM Re: Shell and quotes
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Well done. So what we have here then is yet
another thing that has to be wrapped in @INWIN
and @DOS ? [Wink] Wonder if this syntax is
backward compatible with NT4 ...

-Shawn

[ 08. July 2003, 03:23: Message edited by: Shawn ]

Top
#102633 - 2003-07-08 03:27 AM Re: Shell and quotes
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
let me check..back in a few minutes...
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#102634 - 2003-07-08 03:38 AM Re: Shell and quotes
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
SHELL '%COMSPEC% /C ""C:\data\N F\NOTEPAD.EXE" "%TMP%\LOGON.LOG"" '

Shawn, this also seemed to work on my NT4 SP6a server.

Note: %TMP% is not a long file name however.

[ 08. July 2003, 03:40: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#102635 - 2003-07-08 04:07 AM Re: Shell and quotes
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Minor observation.

Your path to NOTEPAD.EXE is wrong, but I think it does illustrate the intent of this thread.

An executable or associated program should be able to support the parameters discussed if properly '"quoted"'.

code:
 SHELL '%COMSPEC% /C ""%systemroot%\SYSTEM32\NOTEPAD.EXE" "%USERPROFILE%\TEXT.TXT"" ' 



[ 08. July 2003, 04:30: Message edited by: NTDOC ]

Top
#102636 - 2003-07-09 12:07 AM Re: Shell and quotes
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Good grief, what a mess.

Can you simplify/standardise it by using the "escape" carat character (^)?

Top
#102637 - 2003-07-09 12:15 AM Re: Shell and quotes
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
richard, how come you say it's mess?
I think this is not complex enough to start playing with escape...

and didn't it have also limitation?
something that it's only working on NT-based systems?
_________________________
!

download KiXnet

Top
Page 1 of 2 12>


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 811 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.094 seconds in which 0.063 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org