[Cialug] OT: Interesting "feature" in Windows
Tim Wilson
tim_linux at wilson-home.com
Tue Sep 25 17:28:11 CDT 2007
On 9/25/07, David Champion <dchampion at visionary.com> wrote:
>
> Back in the good old days when I was writing Windows desktop apps... I
> used to always get around this by putting quotes around the path names.
> This worked, IIRC in Visual Basic and Visual FoxPro.
Yeah, I tried putting double quotes around it (actually, escaped double
quotes so sprintf() didn't have a problem with it). But system() seemed to
strip out "some" of the double quotes, not all. I had double quotes around
the path to the batch file, and an argument to the batch file. It appeared
to remove the first double quote of the batch file, and the last double
quote of the argument. I still have to put double quotes in the argument to
putenv(), but it does work. If I put into system() what I put into
putenv(), it doesn't. So my code went from:
sprintf(cmd_line, "\"%s%s\" \"%s\" %s", directory_to_batch_file,
name_of_batch_file, arg_to_batch_file1, arg_to_batch_file2);
why = system(cmd_line);
to
sprintf(cmd_line, "DEST_DIR=\"%s\"", directory_to_batch_file);
putenv(cmd_line);
sprintf(cmd_line, "%%DEST_DIR%%%s \"%s\" %s", name_of_batch_file,
arg_to_batch_file1, arg_to_batch_file2);
why = system(cmd_line);
Wow, gotta love all those percents and double quotes! Note the "from" code
was what I was trying, when system() complained about it.
I also tried using the short path (using Foo~1 instead of "Foo Bar"). The
"~n" also seemed to get stripped by system().
How about people putting single quotes in filenames, like "This is
> Dave's File.doc". Who would do a thing like that? Had that blow up a PHP
> script recently. Grrr...
>
> -dc
>
> Nathan C. Smith wrote:
> > And that was all we got from Tim as agents from Redmond beat down the
> door
> > and took him prisoner.
> >
> > -Nate
> >
> >
> > _____
> >
> > From: Tim Wilson [mailto:tim_linux at wilson-home.com]
> > Sent: Tuesday, September 25, 2007 4:47 PM
> > To: cialug at cialug.org
> > Subject: [Cialug] OT: Interesting "feature" in Windows
> >
> >
> > I ran across a problem today, that I thought some of you might enjoy. A
> > customer was running a product we talk to in a directory like
> "C:\Program
> > Files\Foo Bar\Foo2". In this directory, my app runs a batch file. The
> > easiest way to execute the batch file from a C program is to call
> system(),
> > right? That's great, except it has a problem with spaces. No problem,
> I'll
> > put escaped double quotes around the argument to system(). That too,
> did
> > not work. After doing some Googling, I found something that sounds like
> > others are experiencing (someone created a bug
> >
> >
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > Cialug mailing list
> > Cialug at cialug.org
> > http://cialug.org/mailman/listinfo/cialug
>
>
> _______________________________________________
> Cialug mailing list
> Cialug at cialug.org
> http://cialug.org/mailman/listinfo/cialug
>
--
Tim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://cialug.org/pipermail/cialug/attachments/20070925/07748c74/attachment.htm
More information about the Cialug
mailing list