09-29-2010 09:56 AM
Have you tried enclosing the pathname in quotes? This is a general Windows rule to have programs correctly handle long file names with embedded spaces.
Using '\042' will permit you to add proper quotes to the pathname, for example: strcpy (a, "\042This is a test\042"); creates a string with trailing and leading quotes.
09-29-2010 11:55 PM - edited 09-29-2010 11:57 PM
Hi, Roberto,
The command requires no quotes, and Hex path follows the command /GF. For example,
cd d:\Data\
pk2cmd.exe /PPIC18F2320 /GFD:\1.hex>>d:\1.txt
If I change Hex file to path D:\New folder\data\VControlWithConfig091010.hex, bat is expected to be
cd d:\Data\
pk2cmd.exe /PPIC18F2320 /GFD:\New folder\data\VControlWithConfig091010.hex>>d:\1.txt
That’s the main reason I posted parameter % doesn’t accept space.
To use string D:\New folder\data\VControlWithConfig091010.hex>>D:\1.txt, I have to divide it into 2 parts for there is one space (“New folder”), and change 111.bat to below
cd D:\New folder\data
pk2cmd.exe /PPIC18F2320 /GF%1 %2
So I have to pass the path strings like below,
//pass strings before space to cmd
strcat(cmd,"D:\\New");
//append the rest after space to cmd
strcat(cmd,"folder\\data\\VControlWithConfig091010.hex>>D:\\1.txt");
LaunchExecutableEx(cmd,LE_SHOWNORMAL,&handle);
Delay(10);
RetireExecutableHandle(handle);
I tried and it works.
Furthermore, if someone wants to save log to D:\...\1.txt, likely I have to separate the path to more parts if there are spaces in the path string.
If so, I prefer my own approach I was using, to update bat file each time before executing it.
09-30-2010 12:20 AM - edited 09-30-2010 12:21 AM
Just one note: have you tried with a string like
strcpy(cmd,"111.bat \042D:\\New folder\\data\\VControlWithConfig091010.hex>>D:\\1.txt\042");
LaunchExecutableEx(cmd,LE_SHOWNORMAL,&handle);
and with a single %q inside the batch file?
It's not that your program requires quotes, it's that Windows requires quotes to correctly treat long file names.
09-30-2010 10:02 AM
Hi, Roberto,
Thank you. I tried your suggestion just now and no surprise.
I'd like to capture it for more review but cmd window flashes and then disappear so quick!.
Additionally, if the command can execute without any syntax error, I'll get a txt file D:\1.txt. There is no D:\1.txt following your advice actually.
BTW, I can't find detailed description for %q. Obviously, I'm not familiar with command line.
10-01-2010 08:10 AM
Hi labc,
I made some tests with a simple batch file that lists a directory to an output file and had no problems even in case of pathnames with spaces. I am attaching the batch file and some lines of code that you can paste and execute in CVI interactive window; place the batch file in a folder with spaces in the pathname (i.e. "c:\new folder\") and execute the code: the program will let you browse to the batch file and execute it creating the output file in the same folder.
As you can see, I have added the double quotes in every case: they are harmless in case of simple pathnames. You may want to scan the pathname for spaces and add quotes only in that case, but in my opinion this is a useless task.
BTW: to have a batch file pause before in some place simply add a "pause" command somwhere in it. ![]()