Sponsored Content
Homework and Emergencies Homework & Coursework Questions How to use a execvp-call to do "grep PATH"? Post 302364156 by andersbranderud on Thursday 22nd of October 2009 07:52:51 AM
Old 10-22-2009
Problem solved! How to use a execvp-call to do "grep PATH"?

Hello!
I am learning how to use the function execvp. I have read through the UNIX manual.
I have a process. I run execvp and I command it to do “printenv”. It works fine.
Before I do the execvp-call I pipe STDOUT to go to a specific pipe. After that I restore STDOUT. I read that pipe in another process. I have tested it and it works.

Now in this other process I want to do execvp again and I want to command execvp to do “grep ...”.
I don't succeed in doing this.

Here is some of my code:
char* environment_variables_vector[60];
My function call is this: execvp ("grep", environment_variables_vector)

Environment_variables_vector have this format:
Position 0 is a pointer to the string “grep PATH”
Position 1 is a pointer to: A nulterminated string containing an environment variable
Position 2 is a pointer to: Another nulterminated string containing another environment variable
..etcetera, up to
Position 52 is a pointer to: Another nulterminated string containing another environment variable.

When I run the program it doesn't run the code after the execvp-call.

4. School (University) and Course Number:
Royal Technical Highschool, ID2206

Thanks for your help!

EDIT: Problem solved!

Anders Branderud
proofofaCreator.wordpress.com

Last edited by andersbranderud; 10-23-2009 at 06:45 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

grep to find content in between curly braces, "{" and "},"

problem String ~~~~~~~~~~~~~~~~~~ icecream= { smart peopleLink "good" LC "happy" , smartpeopleLink "dull" LC "sad" } aend = {smart vc4 eatr kalu} output needed ~~~~~~~~~~~~~~~~~~ smart peopleLink "good" LC "happy" , smartpeopleLink "dull" LC "sad" smart vc4... (4 Replies)
Discussion started by: keshav_rk
4 Replies

2. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

3. Shell Programming and Scripting

ls -laR | grep "^-" | awk '{print $9}'| grep "$.txt"

Hi, I don't know hot to make this command work: ls -laR | grep "^-" | awk '{print $9}'| grep "$.txt" It should return the list of file .txt It's important to search .txt at the end of the line, becouse some file name have "txt" in their name but have other extensions (13 Replies)
Discussion started by: DNAx86
13 Replies

4. AIX

xx=`date +"%a %b %d"`;rsh xxx grep "^$XX" zzz ?

AIX 4.2 I am trying to do an rsh grep to search for date records inside server logs by doing this : xx=`date +"%a %b %d"` rsh xxx grep "^$XX" zzz gives : grep: 0652-033 Cannot open Jun. grep: 0652-033 Cannot open 11. But if I do : xx=`date +"%a %b %d"` grep "^$XX" zzz it works... (2 Replies)
Discussion started by: Browser_ice
2 Replies

5. Shell Programming and Scripting

ps -ef | grep "string1" "string2" " "string3"

Hi all, can any one suggest me the script to grep multiple strings from ps -ef pls correct the below script . its not working/ i want to print OK if all the below process are running in my solaris system. else i want to print NOT OK. bash-3.00$ ps -ef | grep blu lscpusr 48 42 ... (11 Replies)
Discussion started by: steve2216
11 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Shell Programming and Scripting

Problem with "find" and "grep" command

I want to list all files/lines which except those which contain the pattern ' /proc/' OR ' /sys/' (mind the leading blank). In a first approach I coded: find / -exec ls -ld {} | grep -v ' /proc/| /sys/' \; > /tmp/list.txt But this doesn't work. I got an error (under Ubuntu): grep:... (5 Replies)
Discussion started by: pstein
5 Replies

8. Shell Programming and Scripting

"find . -printf" without prepended "." path? Getting path to current working directory?

If I enter (simplified): find . -printf "%p\n" then all files in the output are prepended by a "." like ./local/share/test23.log How can achieve that a.) the leading "./" is omitted and/or b.) the full path to the current directory is inserted (enclosed by brackets and a blank)... (1 Reply)
Discussion started by: pstein
1 Replies

9. Shell Programming and Scripting

grep with "[" and "]" and "dot" within the search string

Hello. Following recommendations for one of my threads, this is working perfectly : #!/bin/bash CNT=$( grep -c -e "some text 1" -e "some text 2" -e "some text 3" "/tmp/log_file.txt" ) Now I need a grep success for some thing like : #!/bin/bash CNT=$( grep -c -e "some text_1... (4 Replies)
Discussion started by: jcdole
4 Replies

10. Shell Programming and Scripting

find . -path "*_nobackup*" -prune -iname "*.PDF" \( ! -name "*_nobackup.*" \)

These three finds worked as expected: $ find . -iname "*.PDF" $ find . -iname "*.PDF" \( ! -name "*_nobackup.*" \) $ find . -path "*_nobackup*" -prune -iname "*.PDF" They all returned the match: ./folder/file.pdf :b: This find returned no matches: $ find . -path "*_nobackup*" -prune... (3 Replies)
Discussion started by: wolfv
3 Replies
EXEC(3) 						     Linux Programmer's Manual							   EXEC(3)

NAME
execl, execlp, execle, execv, execvp - execute a file SYNOPSIS
#include <unistd.h> extern char **environ; int execl(const char *path, const char *arg, ...); int execlp(const char *file, const char *arg, ...); int execle(const char *path, const char *arg , ..., char * const envp[]); int execv(const char *path, char *const argv[]); int execvp(const char *file, char *const argv[]); DESCRIPTION
The exec family of functions replaces the current process image with a new process image. The functions described in this manual page are front-ends for the function execve(2). (See the manual page for execve for detailed information about the replacement of the current process.) The initial argument for these functions is the pathname of a file which is to be executed. The const char *arg and subsequent ellipses in the execl, execlp, and execle functions can be thought of as arg0, arg1, ..., argn. Together they describe a list of one or more pointers to null-terminated strings that represent the argument list available to the executed program. The first argument, by convention, should point to the file name associated with the file being executed. The list of arguments must be terminated by a NULL pointer. The execv and execvp functions provide an array of pointers to null-terminated strings that represent the argument list available to the new program. The first argument, by convention, should point to the file name associated with the file being executed. The array of pointers must be terminated by a NULL pointer. The execle function also specifies the environment of the executed process by following the NULL pointer that terminates the list of argu- ments in the parameter list or the pointer to the argv array with an additional parameter. This additional parameter is an array of point- ers to null-terminated strings and must be terminated by a NULL pointer. The other functions take the environment for the new process image from the external variable environ in the current process. Some of these functions have special semantics. The functions execlp and execvp will duplicate the actions of the shell in searching for an executable file if the specified file name does not contain a slash (/) character. The search path is the path specified in the environment by the PATH variable. If this variable isn't specified, the default path ``:/bin:/usr/bin'' is used. In addition, certain errors are treated specially. If permission is denied for a file (the attempted execve returned EACCES), these functions will continue searching the rest of the search path. If no other file is found, however, they will return with the global variable errno set to EACCES. If the header of a file isn't recognized (the attempted execve returned ENOEXEC), these functions will execute the shell with the path of the file as its first argument. (If this attempt fails, no further searching is done.) RETURN VALUE
If any of the exec functions returns, an error will have occurred. The return value is -1, and the global variable errno will be set to indicate the error. FILES
/bin/sh ERRORS
All of these functions may fail and set errno for any of the errors specified for the library function execve(2). SEE ALSO
sh(1), execve(2), fork(2), environ(5), ptrace(2) COMPATIBILITY
On some other systems the default path (used when the environment does not contain the variable PATH) has the current working directory listed after /bin and /usr/bin, as an anti-Trojan-horse measure. Linux uses here the traditional "current directory first" default path. The behavior of execlp and execvp when errors occur while attempting to execute the file is historic practice, but has not traditionally been documented and is not specified by the POSIX standard. BSD (and possibly other systems) do an automatic sleep and retry if ETXTBSY is encountered. Linux treats it as a hard error and returns immediately. Traditionally, the functions execlp and execvp ignored all errors except for the ones described above and ENOMEM and E2BIG, upon which they returned. They now return if any error other than the ones described above occurs. CONFORMING TO
execl, execv, execle, execlp and execvp conform to IEEE Std1003.1-88 (``POSIX.1''). BSD MANPAGE
1993-11-29 EXEC(3)
All times are GMT -4. The time now is 04:31 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy