"~" 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 OSF1
va_start
varargs(3) Library Functions Manual varargs(3)NAME
varargs, va_arg, va_start, va_end - Handles a variable-length parameter list
LIBRARY
Standard C Library (libc.a)
SYNOPSIS
#include <varargs.h>
va_alist va_dcl void va_start ( va_alist argp ); type va_arg ( va_alist argp, type ); void va_end ( va_alist argp );
PARAMETERS
argp Specifies a variable that the varargs macros use to keep track of the current location in the parameter list. Do not modify this
variable.
type Specifies the type to which the expected argument will be converted when passed as an argument. Unsigned char or short arguments
are converted to unsigned int, and float arguments are converted to double. Different types can be mixed, but it is up to the rou-
tine to know what type of argument is expected because the type cannot be determined at run time.
DESCRIPTION
NOTE: When writing new code, it is recommended that you use stdarg instead of varargs. They both perform the same function, but stdarg is
standards-compliant and varargs complies only with BSD conventions.
The varargs set of macros allows you to write portable functions that accept a variable number of parameters. Subroutines that have vari-
able-length parameter lists (such as the printf() function), but that do not use the varargs macros, are inherently nonportable because
different systems use different parameter-passing conventions.
The varargs macros are as follows:
va_alist()
Defines the type of the variable used to traverse the list.
va_start()
Initializes argp to point to the beginning of the list. The va_start() macro will be invoked before any access to the unnamed argu-
ments.
va_arg()
Returns the next parameter in the list pointed to by argp.
va_end()
Cleans up at the end.
Your function can traverse, or scan, the parameter list more than once. Start each traversal with a call to va_start() and end it with
va_end().
EXAMPLE
The following example is a possible implementation of the execl() function:
#include <varargs.h>
#define MAXargS 100
/*
** execl is called by
** execl(file, arg1, arg2, . . . , (char *) 0);
*/
execl(va_alist)
va_dcl
{ va_list ap;
char *file;
char *args[MAXargS];
int argno = 0;
va_start(ap);
file = va_arg(ap, char *);
while ((args[argno++] = va_arg(ap, char *)) != (char *) 0)
; /* Empty loop body */
va_end(ap);
return (execv(file, args));
}
NOTES
The calling routine is responsible for specifying the number of parameters because it is not always possible to determine this from the
stack frame. For example, the execl() function is passed a null pointer to signal the end of the list. The printf() function determines the
number of parameters from its fmt parameter.
AES Support Level: Temporary use
RELATED INFORMATION
Functions: exec(2), printf(3), stdarg(3), vprintf(3) delim off
varargs(3)