By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,370 Members | 1,512 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,370 IT Pros & Developers. It's quick & easy.

system call in VC

P: n/a
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

Dec 16 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
ka*****************@yahoo.ca 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.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Dec 16 '05 #2

P: n/a
ka*****************@yahoo.ca wrote:

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"

--
pete
Dec 16 '05 #3

P: n/a
pete said:
Try replacing "ls -al" with "dir -al"


Are you *sure* dir takes -al? I'm not.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Dec 16 '05 #4

P: n/a
pete wrote:
ka*****************@yahoo.ca wrote:
#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"


Bad advice. The closest equivalent for "ls -al" is "dir /a".

--
Simon.
Dec 16 '05 #5

P: n/a
Richard Heathfield <in*****@invalid.invalid> writes:
pete said:
Try replacing "ls -al" with "dir -al"


Are you *sure* dir takes -al? I'm not.


It does if you have a file in the current directory named "-al".

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Dec 16 '05 #6

P: n/a
Check whether the program has rihgts to execute the command attribute
'-a'.

Try giving the absolute path.

Dec 16 '05 #7

P: n/a
ka*****************@yahoo.ca writes:
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
Dec 16 '05 #8

P: n/a
Keith Thompson wrote:

Richard Heathfield <in*****@invalid.invalid> writes:
pete said:
Try replacing "ls -al" with "dir -al"


Are you *sure* dir takes -al? I'm not.


It does if you have a file in the current directory named "-al".


That would have to be the case ;)

--
pete
Dec 16 '05 #9

P: n/a
"ab********@yahoo.co.in" <ab********@yahoo.co.in> writes:
Check whether the program has rihgts to execute the command attribute
'-a'.

Try giving the absolute path.


What program?

Please read <http://cfaj.freeshell.org/google/>.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Dec 16 '05 #10

P: n/a
ka*****************@yahoo.ca 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.

--
A+

Emmanuel Delahaye
Dec 16 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.