Sponsored Content
Top Forums UNIX for Dummies Questions & Answers how to run a shell command from C program? Post 6054 by abdul on Wednesday 29th of August 2001 04:47:19 AM
Old 08-29-2001
how to run a shell command from C program?

Hi mates,

i am trying to use the C execvp command to run a shell program like this:

.....
char input [25];
printf("enter your command");
scanf("%ds",input)
execvp input
....

Compilation is ok but when i run it raise the error :
Segmentation Error ...

your help will be appreciated.

Abdul
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

want to run different files under the same program using shell script

suppose have different files 1.1 2.2 3.3 4.4 5.5 All the files have to run under the same command say tr -d '\n' so how to run all the files under the same command by using shell script (3 Replies)
Discussion started by: cdfd123
3 Replies

2. Shell Programming and Scripting

Run shell program in perl

Hello , I want to run some shell scripts in my perl script. I need to read the script's name from a file ( this file includes the name of all the scripts) and run the script one by one.. Please let me know how to go .. Thanks in advance, Radha (5 Replies)
Discussion started by: s123.radha
5 Replies

3. Shell Programming and Scripting

Run a command on new created shell

Hi I am using a command "script" to capture the output of a command my script is #/bin/sh script filename.txt ./execute_some_script.sh exit exit Now my problem is that when my script run "script filename.txt" its fork a new shell and after the no other command execute The remaining... (2 Replies)
Discussion started by: sushantnirwan
2 Replies

4. Shell Programming and Scripting

Run a command in a special shell

Hi there, Imagine we have to run a command in python shell from a perl script. 1 #!/usr/bin/perl 2 use strict; 3 my @con; 4 @con = `python`; 5 #?????print `print 'salaam'`;???? What's suitable situation for fifth line? Thanks in advance. (4 Replies)
Discussion started by: Zaxon
4 Replies

5. Shell Programming and Scripting

Run shell script from C program by calling fork and execl

I need to write a c program that uses the fork and excel system calls to run the shell script mode invoked like this: "./mode 644 ls -l" (that is the argumetns will always be 644 ls -l) here's the mode script: #!/bin/sh octal="$1" shift find . -maxdepth 1 -perm $octal -exec $@ {} \; ... (3 Replies)
Discussion started by: computethis
3 Replies

6. Shell Programming and Scripting

Shell script to run a python program on multiple entries in a file

Hello I am trying to run a python program using shell script, which takes a single argument from a file. This file has one entry per line : 1aaa 2bbb 3ccc 4ddd 5eee ... ... ... My shell script runs the program, only for the last entry : #!/bin/sh IFS=$'\n' for line in $(cat... (2 Replies)
Discussion started by: ad23
2 Replies

7. Shell Programming and Scripting

Help to hide shell terminal and run prompt program after ssh login for specified user

Hey guys, I have some task from my office to lock user on the specified directory after the user logged on using ssh. And then run prompt program to fill the required information. Yeah, just like an ATM system. My question: How could I do those?? AFAIK I have to edit the ~./bashrc. But the... (1 Reply)
Discussion started by: franzramadhan
1 Replies

8. UNIX Desktop Questions & Answers

command to run another shell on top of your default shell?

Can someone point me to the right command to to run another shell on top of your default shell? Thanks PS If admin sees this It is not home work. I am old man who wants to learn unix in my spare time. I CURRENTLY DO NOT GO SCHOOL, COLLEGE OR UNIVERSITY. (2 Replies)
Discussion started by: Bill Thompson
2 Replies

9. Shell Programming and Scripting

Perl program to run a Shell script issues...

Hi all, I have the following Perl script which is intended to run a Shell script and generate some logging for the purposes of tracking weather or not the script ran. I get an error, of course, since I don't know what I'm doing really. Here is the code: #!/opt/perl/bin/perl -w ... (14 Replies)
Discussion started by: zixzix01
14 Replies

10. Shell Programming and Scripting

Read files in shell script code and run a C program on those files

HI, I am trying to implement a simple shell script program that does not make use of ls or find commands as they are quite expensive on very large sets of files. So, I am trying to generate the file list myself. What I am trying to do is this: 1. Generate a file name using shell script, for... (2 Replies)
Discussion started by: shoaibjameel123
2 Replies
EXECL(3)						     Library Functions Manual							  EXECL(3)

NAME
execl, execv, execle, execlp, execvp, exec, execve, exect, environ - execute a file SYNOPSIS
execl(name, arg0, arg1, ..., argn, 0) char *name, *arg0, *arg1, ..., *argn; execv(name, argv) char *name, *argv[]; execle(name, arg0, arg1, ..., argn, 0, envp) char *name, *arg0, *arg1, ..., *argn, *envp[]; exect(name, argv, envp) char *name, *argv[], *envp[]; extern char **environ; DESCRIPTION
These routines provide various interfaces to the execve system call. Refer to execve(2) for a description of their properties; only brief descriptions are provided here. Exec in all its forms overlays the calling process with the named file, then transfers to the entry point of the core image of the file. There can be no return from a successful exec; the calling core image is lost. The name argument is a pointer to the name of the file to be executed. The pointers arg[0], arg[1] ... address null-terminated strings. Conventionally arg[0] is the name of the file. Two interfaces are available. execl is useful when a known file with known arguments is being called; the arguments to execl are the char- acter strings constituting the file and the arguments; the first argument is conventionally the same as the file name (or its last compo- nent). A 0 argument must end the argument list. The execv version is useful when the number of arguments is unknown in advance; the arguments to execv are the name of the file to be exe- cuted and a vector of strings containing the arguments. The last argument string must be followed by a 0 pointer. The exect version is used when the executed file is to be manipulated with ptrace(2). The program is forced to single step a single instruction giving the parent an opportunity to manipulate its state. On the VAX-11 this is done by setting the trace bit in the process status longword. Exect is not available on the PDP-11. When a C program is executed, it is called as follows: main(argc, argv, envp) int argc; char **argv, **envp; where argc is the argument count and argv is an array of character pointers to the arguments themselves. As indicated, argc is convention- ally at least one and the first member of the array points to a string containing the name of the file. Argv is directly usable in another execv because argv[argc] is 0. Envp is a pointer to an array of strings that constitute the environment of the process. Each string consists of a name, an "=", and a null-terminated value. The array of pointers is terminated by a null pointer. The shell sh(1) passes an environment entry for each global shell variable defined when the program is called. See environ(7) for some conventionally used names. The C run-time start-off routine places a copy of envp in the global cell environ, which is used by execv and execl to pass the environment to any subprograms executed by the current program. Execlp and execvp are called with the same arguments as execl and execv, but duplicate the shell's actions in searching for an executable file in a list of directories. The directory list is obtained from the environment. FILES
/bin/sh shell, invoked if command file found by execlp or execvp SEE ALSO
execve(2), fork(2), environ(7), csh(1) DIAGNOSTICS
If the file cannot be found, if it is not executable, if it does not start with a valid magic number (see a.out(5)), if maximum memory is exceeded, or if the arguments require too much space, a return constitutes the diagnostic; the return value is -1. Even for the super- user, at least one of the execute-permission bits must be set for a file to be executed. BUGS
If execvp is called to execute a file that turns out to be a shell command file, and if it is impossible to execute the shell, the values of argv[0] and argv[-1] will be modified before return. 4.2 Berkeley Distribution August 4, 1987 EXECL(3)
All times are GMT -4. The time now is 06:16 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy