LinuxQuestions.org
Help answer threads with 0 replies.
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 09-02-2004, 10:05 AM   #1
tonyfreeman
Member
 
Registered: Sep 2003
Location: Fort worth, TX
Distribution: Debian testing 64bit at home, EL5 32/64bit at work.
Posts: 196

Rep: Reputation: 30
execlp command syntax help


I'm forking a process to run a backup command. I've been trying to figure out how to use one of the "exec" commands to do the equivalent of the code below:
Code:
tar czf /tmp/2004Sep01.tar.gz `find /data/local/2004/Sep/01 -daystart -cmin +1420 -cmin -2290`
. . . but I'm having trouble figuring this out.

To start out, I've tried to figure out how to just do the find command part, but this attempt doesn't work:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <glib.h>
int main () {
  g_print("Executing command\n");
  execlp("find", "find", "/data/local/2004/Sep/01", "-daystart", "-cmin", "+1000", "-cmin", "+2000", ">/tmp/find.text", NULL);
  g_print("End of command\n");
  return EXIT_SUCCESS;
}
Could you please help me figure out how to properly use one of the "exec" commands to do what I want?

Possibly running a tar/find command isn't what I should be doing? Is there a "C" way to do it?

--Tony

Last edited by tonyfreeman; 09-02-2004 at 11:21 AM.
 
Old 09-02-2004, 01:25 PM   #2
KneeLess
Member
 
Registered: May 2003
Distribution: Debian GNU/Linux 3.0 Sid, OpenBSD 3.5
Posts: 190

Rep: Reputation: 30
man 3 exec

One thing I noticed is that the first arguement of execlp() is the filename of the file to be executed, maybe use the full pathname (/usr/bin/find). And I don't believe you need the "find" twice, just once will do.

Last edited by KneeLess; 09-02-2004 at 01:28 PM.
 
Old 09-02-2004, 01:39 PM   #3
tonyfreeman
Member
 
Registered: Sep 2003
Location: Fort worth, TX
Distribution: Debian testing 64bit at home, EL5 32/64bit at work.
Posts: 196

Original Poster
Rep: Reputation: 30
OK ... I just figured out that if I removed the ">/tmp/find.text" part .... the find command works.
Code:
execlp("find", "find", "/data/2004/Sep/01", "-daystart", "-cmin", "+1000", "-cmin", "+2000", NULL);
I wonder why it didn't like sending the output to the text file?

Anyway ... Now I need to adjust things in order to make the tar command run off of the find command.

Has anyone done this sort of thing before? Any ideas or examples I can use to do it?

Thanks for reading ;-)

--Tony
 
Old 09-02-2004, 01:41 PM   #4
KneeLess
Member
 
Registered: May 2003
Distribution: Debian GNU/Linux 3.0 Sid, OpenBSD 3.5
Posts: 190

Rep: Reputation: 30
Quote:
I wonder why it didn't like sending the output to the text file?
As far as I know, execlp() doesn't use bash, which I should've seen, and the last part is bash syntax.
 
Old 09-02-2004, 08:54 PM   #5
mirradric
Member
 
Registered: May 2004
Location: Singapore
Distribution: Debian woody and debian sarge
Posts: 188

Rep: Reputation: 31
Quote:
One thing I noticed is that the first arguement of execlp() is the filename of the file to be executed, maybe use the full pathname (/usr/bin/find). And I don't believe you need the "find" twice, just once will do.
You do need to have find twice, once for the program to execute and the second for the the zero argument (i.e. the name of the program).

And you don't need to use the full pathname if the command is in your path. The p family does it for you.

If you need to redirect the output then use dup2 to change the stdout to that of a file descriptor of a file.


Last edited by mirradric; 09-02-2004 at 08:58 PM.
 
Old 09-07-2004, 09:09 AM   #6
heluani
LQ Newbie
 
Registered: Aug 2004
Distribution: Fedora Core 2
Posts: 16

Rep: Reputation: 0
If you type at command prompt

~[1]$ mybin -myarg > mypath/myfile

Then mybin is executed with only two arguments (agrv[0]="mybin" and argv[1]="-myarg") and the shell takes care of the rest. You were sending "> mypath/myfile" as an argument to "mybin" who doesn't understand that. You should redirect the output before or in the case of find, send a parameter like "-fprintf", look at the man page for find.

R.
 
  


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
cp command syntax plisken Linux - General 3 11-09-2005 02:51 PM
Command Syntax Ask swan2925 Linux - Software 1 06-06-2005 09:50 AM
command syntax Jeebizz Slackware 1 04-14-2005 10:55 PM
Execlp and "ln" command Spooky Programming 1 01-09-2004 09:26 AM
Command Syntax BittaBrotha Linux From Scratch 4 08-15-2002 12:36 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:15 PM.

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
Open Source Consulting | Domain Registration