English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

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

2006-09-11 22:01:05 · 4 answers · asked by Gopinath M 3 in Computers & Internet Programming & Design

4 answers

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.

2006-09-11 22:37:33 · answer #1 · answered by Balk 6 · 1 0

Gopinath M This link might help you understand

http://www.google.co.uk/search?hl=en&q=make+a+C%23+program+run+a+bat+file+using+cmd.exe&btnG=Search&meta=

2006-09-12 06:19:45 · answer #2 · answered by Joe_Young 6 · 0 0

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.

2006-09-12 05:11:15 · answer #3 · answered by Ken H 4 · 0 1

#include
int main(void){
system("cmd.exe batch_file_name.bat");
return 0;
}

2006-09-12 07:34:50 · answer #4 · answered by myururdurmaz 1 · 0 1

fedest.com, questions and answers