Kaushik koneru
Kaushik koneru

Reputation: 11

system call giving not enough memory in c++

I was trying to enter list of files in a file by using command

system("dir *.txt /b :gen> file.txt");

in a c program

this is giving me a error saying "not enough memory"

but when i am writing the same code (dir *.txt /b :gen >file.txt) in cmd it is working fine

and also i tried some other codes also like "cd" they are also giving same error

error is being displayed if i use perror("error");

Upvotes: 0

Views: 248

Answers (1)

unwind
unwind

Reputation: 399833

You can't rely on perror() to correctly report status from a process started using system().

All that perror() does is inspect the value of errno, but that's not set by system().

See the documentation on how to actually catch status information from system().

Upvotes: 1

Related Questions