system function in c

February 27, 2013 at 12:01:46
Specs: Windows 7
if system function shoes error -1 what that's mean, is there any problem like this to save location where it should be save ?
i am using tc , i just make code for dir but not working

See More: system function in c

Report •

February 27, 2013 at 13:48:31
Show us your code and we might be able to answer rather than just guessing. But I'm feeling psychic tonight, so I'll guess you are doing something like

error = system("dir");

Hmm - that's not going to work is it? "dir" is a built-in command in cmd.exe, not an executable file. Try:

error = system("cmd /c dir");

Of course I could be completely wrong.

Edit: Actually, in retrospect, I may indeed be worng. It's a long time since I used Turbo C as I prefer to use compilers that are younger than myself - and I'm no spring chicken. It could just be that you are trying to run the program from within the IDE. This is a known feature and it means you have run out of memory. Try running the standalone .exe file rather than running in the IDE. Better still, implement your own "dir" function rather than using the DOS one. That will be more efficient and will be educational.

Report •

February 27, 2013 at 14:24:44
This VC++ compiled program:
#include <cstdio>
#include <iostream>
int main() {
  std::cout << std::system("echo %CMDCMDLINE%");
  return 0;
C:\Windows\system32\cmd.exe /c echo %CMDCMDLINE%

Whereas std::cout << std::system("dirigible"); gives me:
'dirigible' is not recognized as an internal or external command,
operable program or batch file.

Then again, I am using a compiler that's been updated in the last 20 years, so it could very well be yet another compatibility issue with TC.

How To Ask Questions The Smart Way

Report •

February 27, 2013 at 23:06:31
got it its done now thanks.

Report •
Related Solutions

Ask Question