Friday, July 31, 2009

How to make a C program run a bat file using cmd.exe?

I made a C program that uses simple file handling and types some command in a bat file. Then It runs the bat file using 'system' statement in 'process.h' . The problem is it runs in NTVDM ie suppose if i give the command to run a file in C:\asdfasdfadf.txt, it uses only the eight character of the file name. The batch file works perfectly when run in cmd.exe. Is there any way to start the bat file in cmd using a C program

How to make a C program run a bat file using cmd.exe?
So I guess you're trying to make a DOS program access files with long filenames, right?





Well, I've never tried it, but maybe you can try putting the file name in quotes.


For example, if you want to open a file called


Hello Out There.txt, you would pass this string to your 'open file' C procedure:


"Hello Out There.txt"





My suggestion comes from the fact that if you run command.com and you want to use EDIT.COM to edit a text file with a long filename, you need to put the file name in quotes. Keep in mind that command.com is a DOS program, while cmd.exe is a Windows console program. Cmd.exe allows long file names, while command.com expects 8.3 format.





Another suggestion is to pass the C 'open file' function the mangled 8.3 DOS name that Windows uses for files that use long file names.


The mangled name for Hello Out There.txt would be helloo~1.txt. To get an idea about how the mangled names work, just run command.com and look at all the file names and directory names which use long file names.
Reply:#include %26lt;stdlib.h%26gt;


int main(void){


system("cmd.exe batch_file_name.bat");


return 0;


}
Reply:I haven't done much C in Windows, but you might try fork, and exec the command in the child process. Just a suggestion of a different method, I have no idea if it will make any difference.
Reply:Gopinath M This link might help you understand





http://www.google.co.uk/search?hl=en%26amp;q=m...

floral design

No comments:

Post a Comment