system call in VC

  • Thread starter kaci_tizi_ouzou2000
  • Start date
K

kaci_tizi_ouzou2000

Greetings all.

I am trying to make a system call as on WinXP,

#include <stdlib.h>

int main()
{
system( "ls -al");
}

but it is doing nothing!!

Has anybody ever experienced such a thing!? My belief is there is a
library that was missed when I installed VC but I am not sure.

Any suggestions, hints, pointers etc etc is greatly appreciated.

Cheers
 
R

Richard Heathfield

(e-mail address removed) said:
Greetings all.

I am trying to make a system call as on WinXP,

#include <stdlib.h>

int main()
{
system( "ls -al");
}

but it is doing nothing!!

Has anybody ever experienced such a thing!? My belief is there is a
library that was missed when I installed VC but I am not sure.

Any suggestions, hints, pointers etc etc is greatly appreciated.

Firstly, check that your system has an ls command that accepts the switch
-al. It is quite likely in your case that it does not, since ls isn't a
command normally associated with Windows systems.

Secondly, if your system does support an ls command, consider the
possibility that the system call is executing so quickly that you simply
don't see it. For example, consider doing something like:

system("ls -al > listing.txt");

and then checking for the existence of listing.txt.
 
P

pete

Greetings all.

I am trying to make a system call as on WinXP,

#include <stdlib.h>

int main()
{
system( "ls -al");
}

but it is doing nothing!!

Has anybody ever experienced such a thing!? My belief is there is a
library that was missed when I installed VC but I am not sure.

Any suggestions, hints, pointers etc etc is greatly appreciated.

Try replacing "ls -al" with "dir -al"
 
N

Niklas Norrthon

Greetings all.

I am trying to make a system call as on WinXP,

#include <stdlib.h>

int main()
{
system( "ls -al");
}

but it is doing nothing!!

system() is part of the C standard, but it's effect depends entirely
on the implementation, which means it's off topic here.

Anyway, the system() function returns a value. Save that value, and
read your implementation's documentation to find out what it means.

<OT>
Last time I checked 'ls' wasn't a valid dos/windows command, so
unless there is a file named ls.exe, ls.com, or ls.bat somewhere
I'd expect the system call to fail.
</OT>

/Niklas Norrthon
 
A

abdur_rab7

Check whether the program has rihgts to execute the command attribute
'-a'.

Try giving the absolute path.
 
E

Emmanuel Delahaye

(e-mail address removed) a écrit :
Greetings all.

I am trying to make a system call as on WinXP,

#include <stdlib.h>

int main()
{
system( "ls -al");
}

but it is doing nothing!!

I'm not surprised that the unix commands are not supported by the
Windows shell. Try this :

system( "dir");

also, you may need some pause to see the results :

system( "pause");

Note that this code is standard C (hence on-topic here), but is not
portable.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,172
Messages
2,570,934
Members
47,473
Latest member
ChristelPe

Latest Threads

Top