LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 11-25-2005, 04:54 PM   #1
harisund
Member
 
Registered: Sep 2005
Location: Baton Rouge
Distribution: Ubuntu 5.10
Posts: 74

Rep: Reputation: 15
Making system calls in C++


First, maybe system calls is a wrong word to describe what I am talking about.

While inside a C++ program (or for that matter, even C will be fine) I want to call `ls > FileListing` and then read the FileListing file through the program .

Can it be done?

Basically, I have a lot of directories, and I want to parse all the files in those directories, and then do some indexing of the files.

Does anyone think using a csh would help? If so, in what way? I was wondering if the name is "c" shell, it must have some benefits to C programmers, right?

Thanks a lot

Regards

Hari
 
Old 11-25-2005, 09:06 PM   #2
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 77
Check out "man 3 system" or "man 3 exec" for how to call a shell command from C/C++

However, you can do this directly from C/C++ using the "glob" library call, given "*" as an argument to return all files in a directory. From "man 3 glob":
Code:
       One example of use is the following code, which simulates typing ls -l *.c ../*.c in the shell.

          glob_t globbuf;

          globbuf.gl_offs = 2;
          glob("*.c", GLOB_DOOFFS, NULL, &globbuf);
          glob("../*.c", GLOB_DOOFFS | GLOB_APPEND, NULL, &globbuf);
          globbuf.gl_pathv[0] = "ls";
          globbuf.gl_pathv[1] = "-l";
          execvp("ls", &globbuf.gl_pathv[0]);
Quote:
Does anyone think using a csh would help? If so, in what way? I was wondering if the name is "c" shell, it must have some benefits to C programmers, right?
csh has nothing to do with C, it is just named that because the syntax is similar to C...

Last edited by bulliver; 11-25-2005 at 09:08 PM.
 
Old 11-25-2005, 09:09 PM   #3
zahadumy
Member
 
Registered: May 2005
Location: Cluj, Romania
Distribution: Fedora Core 6
Posts: 226

Rep: Reputation: 31
man 3 exec

Was it helpful?

*** UPDATE ***
Sorry, bulliver was faster than me.

Last edited by zahadumy; 11-25-2005 at 09:10 PM.
 
Old 11-26-2005, 06:15 PM   #4
harisund
Member
 
Registered: Sep 2005
Location: Baton Rouge
Distribution: Ubuntu 5.10
Posts: 74

Original Poster
Rep: Reputation: 15
system was what I was looking for. Thanks a lot.

And by the way, man 3 exec outputs no manual entry for section 3 of exec.

But system works fine.

Thanks a lot !

Regards
hari
 
Old 11-26-2005, 06:58 PM   #5
zahadumy
Member
 
Registered: May 2005
Location: Cluj, Romania
Distribution: Fedora Core 6
Posts: 226

Rep: Reputation: 31
If you type "man 3 exec" on Fedora Core 3 you will see this. I think you get the same output on Slackware 10.1, but I'm not 100% about this. But if system solved your problem, that's fine.

Last edited by zahadumy; 11-26-2005 at 07:00 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
System calls question alltime Programming 1 11-29-2005 09:31 PM
modifying system calls manjiri Linux - Newbie 3 11-07-2005 02:02 PM
Some system calls Spooky Programming 1 11-24-2004 11:17 AM
Making a modem accept calls kater0000 Linux - Networking 2 02-02-2004 06:15 PM
java and system calls aizkorri Programming 6 06-20-2003 02:54 AM


All times are GMT -5. The time now is 07:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration