Sponsored Content
Top Forums Programming code that reads commands from the standard i/p and executes the commands Post 302103730 by Phrozen Smoke on Sunday 21st of January 2007 04:18:48 AM
Old 01-21-2007
code that reads commands from the standard i/p and executes the commands

Hello all,
i've written a small piece of code that will read commands from standard input and executes the commands.
Its working fine and is execting the commands well. Accepting arguments too. e.g
#mkdir <name of the directory>

The problem is that its not letting me change the directory i.e pwd is remaining the same.
what changes should be made in it to let it change the directories too.

Code:
#include <stdio.h>
#include <string.h>
#define MAXLINE 50

int main(void)
{
        char buf[MAXLINE];

        printf("%% ");
        while (fgets(buf, MAXLINE, stdin) != NULL)
        {
                buf[strlen(buf) -1] = 0;
                system(buf);
                printf("%% ");
        }
}

regards
 

10 More Discussions You Might Find Interesting

1. Linux

how to get source code of Unix commands?

Can anyone tell me how/where to get the source code for the unix commands like "ls ,finger,cp....etc" commands . I have tried very hard but failed so far. Thanks JAGDISH MACHHI (4 Replies)
Discussion started by: jagdish.machhi@
4 Replies

2. Shell Programming and Scripting

Can BASH execute commands on a remote server when the commands are embedded in shell

I want to log into a remote server transfer over a new config and then backup the existing config, replace with the new config. I am not sure if I can do this with BASH scripting. I have set up password less login by adding my public key to authorized_keys file, it works. I am a little... (1 Reply)
Discussion started by: bash_in_my_head
1 Replies

3. UNIX for Dummies Questions & Answers

taking a look at the code for some commands

just curious -- I was wondering if it's possible to open the file for a command and look at the code (say for the command more). I've just read about the PATH variable and the type command to find out where the file is, but when I tried to open the file, the terminal exited and logged me out. ... (3 Replies)
Discussion started by: Straitsfan
3 Replies

4. Shell Programming and Scripting

Executing Commands From Non-Standard Path (Changing user's PATH secretely???)

Hi: I have a requirement as below: I have some standard Unix commands modified and kept them in a directory say /usr/clsh/bin. For example I have a script named "ls" kept here which is modified version of "ls" (say it always gives long listing i.e. ls -l). When any user logs on and types... (2 Replies)
Discussion started by: ramesh_samane
2 Replies

5. UNIX for Advanced & Expert Users

Source code for Unix commands

hi Folks!! Just got a question in mind.... Is it possible for us to read the c code of the commands in the bin directory? I work on a LINUX server and i only see executables in the bin directory which i obviously can't read. Please help me regarding this. Thanks in advance and wishing you a very... (2 Replies)
Discussion started by: bdiwakarteja
2 Replies

6. Shell Programming and Scripting

how to run non-standard commands in bash script?

Hello All. I suspect that this will be a clear noob question, but I haven't been able to figure it out using the usual methods, so I turn to you. I've written a script to create input files for the quantum chemistry program NWCHEM. Generally you create an input file and then execute it by... (12 Replies)
Discussion started by: EinsteinMcfly
12 Replies

7. Shell Programming and Scripting

Code for running commands one after other

I need an if code in shell script where it should continue to further commands after succesfully installing the executable file. i.e. /run installer is continuing but in the middle it executes further commands like "cp /root/user which were given after /run installer. I want /runinstaller... (16 Replies)
Discussion started by: sriki32
16 Replies

8. AIX

HACMP: difference between 'cl' commands and 'cli' commands

Hi all, I'm new in this forum. I'm looking for the difference between the HACMP commands with the prefix "cl" and "cli". The first type are under /usr/es/sbin/cluster/sbin directory and the second are under /usr/es/sbin/cluster/cspoc directory. I know that the first are called HACMP for AIX... (0 Replies)
Discussion started by: peppix
0 Replies

9. Shell Programming and Scripting

Differences in printed commands after execution with same code

I have a korn shell script that executes a function which is stored in a common library. In the function there is obviously some code. Here is the line of code in the function in question: temp=`echo $status_cnt|tr -d ` When the shell script executes with set -x, I'm seeing that on most... (2 Replies)
Discussion started by: mjf
2 Replies

10. UNIX for Beginners Questions & Answers

Not able to execute standard commands on centos 7 server

I am not able to run basic commands on my centos 7 server. The PATH variable looks correct I think. I have not seen this before and not sure what to do next. Thank you :). # cd /usr/bin # ls bash: ls: command not found... Similar command is: 'lz' nano ~/.bashrc bash: nano: command not... (6 Replies)
Discussion started by: cmccabe
6 Replies
setbuf(3s)																setbuf(3s)

Name
       setbuf, setbuffer, setlinebuf, setvbuf - assign buffering to a stream

Syntax
       #include <stdio.h>

       void setbuf(stream, buf)
       FILE *stream;
       char *buf;

       void setbuffer(stream, buf, size)
       FILE *stream;
       char *buf;
       int size;

       void setlinebuf(stream)
       FILE *stream;

       int setvbuf(stream, buf, type, size)
       FILE *stream;
       char *buf;
       int type; size_t size;

Description
       The three types of buffering available are unbuffered, block buffered, and line buffered.  When an output stream is unbuffered, information
       appears on the destination file or terminal as soon as written; when it is block buffered many characters are saved up  and  written  as  a
       block;  when  it  is line buffered characters are saved up until a new line is encountered or input is read from stdin.	The routine may be
       used to force the block out early.  Normally all files are block buffered.  For further information, see A buffer is obtained from upon the
       first  or  on  the  file.   If  the  standard stream stdout refers to a terminal it is line buffered.  The standard stream stderr is always
       unbuffered.

       The routine is used after a stream has been opened but before it is read or written.  The character array buf is used instead of  an  auto-
       matically  allocated  buffer.  If buf is the constant pointer NULL, input/output will be completely unbuffered.	A manifest constant BUFSIZ
       tells how big an array is needed:
       char buf[BUFSIZ];

       The routine, an alternate form of is used after a stream has been opened but before it is read or written.  The character array	buf  whose
       size  is  determined  by  the  size  argument  is  used instead of an automatically allocated buffer.  If buf is the constant pointer NULL,
       input/output will be completely unbuffered.

       The routine is used to change stdout or stderr from block buffered or unbuffered to line buffered.  Unlike and it can be used at  any  time
       that the file descriptor is active.

       The  routine  may  be  used  after a stream has been opened but before it is read or written.  Type determines how stream will be buffered.
       Legal values for type, defined in stdio.h are:

	_IOFBF	      causes input/output to be fully buffered.

	_IOLBF	      causes output to be line buffered; the buffer will be flushed when a new line is written, the buffer is full,  or  input	is
		      requested.

	_IONBF	      causes input/output to be completely unbuffered.

       If  buf is not the NULL pointer, the array it points to will be used for buffering, instead of an automatically allocated buffer.  The size
       specifies the size of the buffer to be used.  The constant BUFSIZ in <stdio.h> is suggested as a good  buffer  size.   If  input/output	is
       unbuffered, buf and size are ignored.

       By default, output to a terminal is line buffered and all other input/output is fully buffered.

       A  file	can be changed from unbuffered or line buffered to block buffered by using For further information, see A file can be changed from
       block buffered or line buffered to unbuffered by using followed by with a buffer argument of NULL.

Restrictions
       The standard error stream should be line buffered by default.

       The and functions are not portable to non 4.2 BSD versions of UNIX.

See Also
       malloc(3), fclose(3s), fopen(3s), fread(3s), getc(3s), printf(3s), putc(3s), puts(3s).

																	setbuf(3s)
All times are GMT -4. The time now is 08:50 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy