"~" is a shortcut that shells (like bash) implement. At the "C" api level, you can only use actual relative or absolute paths (no environment variables or anything).
If you wish to implement functionality similar to "~" you must do something like:
Hi!
I'm writing a C program which gets from the command line a shell command (such as "ls" ) and I should execute it.
My Q is: how can I send a command to the shell?
I know I have to use one of the above functions, but I don't know how to use them.
Thanks
eyal (1 Reply)
Hi,
Is it possible to run a program from my C program using only the full pathname?
for example if I wanna call: "ls", so I whould have to use:
execl("/bin/ls", "ls", NULL);
Is it possible to do this using only:
"/bin/ls"
thanks (1 Reply)
Consider the following scenario
program1:
main()
{
......
execl("path","function",...);
.....
}
function()
{
-----
-------
}
Now i want to include the path of function in execl. How to do this.
should the path be the path of function's executable file. If it so how... (1 Reply)
I want to make simultanous sh commands in an exec command
for example I want to counts the lines in a file
wc -l my file.txt | awk -F" " '{print $1}'` works fine in sh but I want to implement it in a c code
the first part works like this
execl("/usr/bin/wc", "wc", "-l", "myfile.txt",... (1 Reply)
Hi,
we would appreciate if any one answer the below query.
void main()
{
printf(“ I am in main\n”);
execl(“/HOME/source/file2”,” /HOME/source/file2”,1,0);
printf(“after execl\n”);
}
How to step the file2 source code in GDB. (2 Replies)
hello everybody
how can i time the execution of execl() command inside my C code?
for example, i wrote..
execl("md5sum","md5sum","myprog",NULL);
i want to count the duration of the execl command!
thanx in advance! (2 Replies)
when execl fails using the command lss, it doesnt go into the next line
execl("/bin/sh", "/bin/sh", "-c", command, NULL);
perror("execl failed"); exit(127);
for some reason the child process just stops and also the parent process also stops
so the line after the line that... (3 Replies)
Hi, I have two programs, one is named "Master" and the other one "slave". What I want to do is , when I execute Master, inside slave will be called by excecl, do some calculations, and send those to the master program... A little example of what I am failing to do:
if ((PID1=fork())==0) { //... (6 Replies)
Hi,
If I write in a c file :
execlp("date","date",NULL);
printf("A\n");
And then run through the terminal would "A" be printed ?
I understood that execlp will exit the program after it finished so the next lines of code won`t be executed afterwards.. Is that true ? (1 Reply)
Discussion started by: uniran
1 Replies
LEARN ABOUT REDHAT
getpwnam
GETPWNAM(3) Linux Programmer's Manual GETPWNAM(3)NAME
getpwnam, getpwuid - get password file entry
SYNOPSIS
#include <pwd.h>
#include <sys/types.h>
struct passwd *getpwnam(const char *name);
struct passwd *getpwuid(uid_t uid);
DESCRIPTION
The getpwnam() function returns a pointer to a structure containing the broken out fields of a line from /etc/passwd for the entry that
matches the user name name.
The getpwuid() function returns a pointer to a structure containing the broken out fields of a line from /etc/passwd for the entry that
matches the user uid uid.
The passwd structure is defined in <pwd.h> as follows:
struct passwd {
char *pw_name; /* user name */
char *pw_passwd; /* user password */
uid_t pw_uid; /* user id */
gid_t pw_gid; /* group id */
char *pw_gecos; /* real name */
char *pw_dir; /* home directory */
char *pw_shell; /* shell program */
};
RETURN VALUE
The getpwnam() and getpwuid() functions return a pointer to the passwd structure, or NULL if the matching entry is not found or an error
occurs.
ERRORS
ENOMEM Insufficient memory to allocate passwd structure.
FILES
/etc/passwd
password database file
CONFORMING TO
SVID 3, POSIX, BSD 4.3
SEE ALSO fgetpwent(3), getgrnam(3), getpwent(3), setpwent(3), endpwent(3), getpw(3), putpwent(3), passwd(5)GNU 1996-05-27 GETPWNAM(3)