LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

what is different between command.com and cmd.exe?

When I use
sprintf(temp, "command /C dir %s /a-d/b/s>C:\\file.txt", path);
system(temp);
it does not work.
But
this works
sprintf(temp, "cmd /C dir %s /a-d/b/s>C:\\file.txt", path);
system(temp);

What am I missing here?
Thanks for your help.
Thanks.
CVI 2010
LabVIEW 2011 SP1
Vision Builder AI 2011 SP1
0 Kudos
Message 1 of 2
(5,242 Views)
COMMAND.COM was the earlier version of the Shell with the basic 8.3 filename conventions.

CMD.EXE is the newer version with support for long filenames.

Type COMMAND /? and CMD /? and look at the difference.

"COMMAND.COM /C SomeLongFileName" might not work as expected where "CMD /C SomeLongFileName" would.

Remember that you have to be specific in the path of the files. If the file your looking for is not in the current directory or in the PATH then the command will fail. Don't assume what the current directory is also. Windows may put you in a directory you didn't expect.

The command your using must be changed slightly to make the COMMAND statement work.
Change the command to

"COMMAND.COM /C dir %s /a-d/b/s>C:\\file.txt"

For some reason you need the ".COM" when using the system() function call. I found COMMAND.COM on my system in C:\WINNT\SYSTEM32\.

Adding the path didn't help.
C:\\WINNT\\SYSTEM32\\COMMAND /C DIR > C:\\FILE.TXT
It specifically needed the ".COM" added which is slightly contrary to the way I think system() should work. It must not consider that .COM is a valid executable name like it considers .EXE.

Also note that the output of the DIR command differs depending on whether your using COMMAND or CMD. Just look at the files that get created. CMD has long filenames, COMMAND has 8.3 filenames.

The help for system() says

Starts running a program and waits for it to exit.
If you do not want to wait for the program to exit,
use the LaunchExecutable() function in the Utility Library.

The executable can be either an MS DOS or MS Windows executable, including *.exe, *.com, *.bat and *.pif
files. The function does not return until the command
terminates, and user keyboard and mouse events are ignored until the command exits. Callbacks for asynchronous events, such as idle events, Windows messages, and VXI interrupts, PostDeferred calls, and DAQ events are called while the command is executing.

If you need to execute a command built into command.com such as copy, dir, etc, you can call LaunchExectuable() with the command:

"command.com /C DosCommand args",

where DosCommand is the shell command you want to be executed.
Refer to your DOS documentation for further help with command.com.

.exe, .com, and .bat DOS programs use the settings in _default.pif (in your Windows directory) when running. You can
change their priority, display options, etc by editing
_default.pif or by creating another pif file. Refer to your
Microsoft Windows documentation for help on creating and editing pif files.


Good Luck
Message 2 of 2
(5,242 Views)