Sponsored Content
Top Forums Programming How to take input from cmd line into file Post 302394528 by migurus on Thursday 11th of February 2010 06:18:50 PM
Old 02-11-2010
man popen

simple example:

Code:
 
FILE *pfp;
if((pfp = popen("ls", "r")) != NULL)
{
    while(fgets(bufffer, sizeof(buffer)-1, pfp))
    {
        printf("I read: %s\n", buffer);
    }
    pclose(pfp);
}

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh: cmd output to input of another script

I want to write a script in KSH that takes the output of one command and redisplays it. Something like: while true do read inpt date +"%I:%M:%S %p <-> $inpt" done and then some how get the output of the ping command to redirect to the input of this script. does that make sense? (2 Replies)
Discussion started by: IMTheNachoMan
2 Replies

2. Shell Programming and Scripting

sed to read line by line and input into another file

I have two files. Fileone contains text string one text string two text string three Filetwo contains Name: Address: Summary: Name: Address: Summary: Name: Address: Summary: I would like to use sed to read each line of file one and put it at the end of the summary line of file... (3 Replies)
Discussion started by: dolacap
3 Replies

3. Shell Programming and Scripting

sed command works from cmd line to standard output but will not write to file

Hi all .... vexing problem here ... I am using sed to replace some special characters in a .txt file: sed -e 's/_<ED>_/_355_/g;s/_<F3>_/_363_/g;s/_<E1>_/_341_/g' filename.txt This command replaces <ED> with í , <F3> with ó and <E1> with á. When I run the command to standard output, it works... (1 Reply)
Discussion started by: crumplecrap
1 Replies

4. Shell Programming and Scripting

How to input the return value (1 or 0) ping cmd to a variable

Hi I would like to ask about my plan script I have this several workstation want to monitor and execute a command without logging it we use "rsh $host "<command>" i create csh script using foreach to loop my several workstation, my problem with the rsh command is if it encounter a... (3 Replies)
Discussion started by: jao_madn
3 Replies

5. UNIX for Dummies Questions & Answers

input URL into cmd with a alias

I want to run wget "URL" -SO /dev/null 2>&1 | grep "HTTP/\\|Age:\\|Last-Modified:" but I want a alias so I can just type mywget and the URL and it will put the url in the right place and give me the output that I want without having to type that over and over again.:wall: I am newbie to all... (2 Replies)
Discussion started by: splitradius
2 Replies

6. Shell Programming and Scripting

run cmd based on input

Hi, This is what I have so far but it seems like a lot more than is necessary because....for example...user presses 2 or 3 ..... the script does the *same* thing it just depends on the directory it has to access....how can I improve this so that the code from 2 and 3 is only put once...? ... (4 Replies)
Discussion started by: holyearth
4 Replies

7. UNIX for Dummies Questions & Answers

passing input into a cmd line that's waiting for a response

Hi, I am writing a little script to update a parameters on JMQ. however the JMQ requires a "y" confirmation to be input as part of the cmd I am running. However I want run this script to offline with no input from a user. it works if a I create a file with with just y in it and pass that in... (3 Replies)
Discussion started by: shropshirehobbi
3 Replies

8. Shell Programming and Scripting

Curl - input line by line from text file

Hi, I've got a text file with hundreds of lines I need to upload to an API via curl, one by one. The text file is like: 2012-08-01 10:45,124 2012-08-02 10:45,132 2012-08-03 10:45,114 I want to get curl to go through the text file sending a post for each line. like: curl --request... (0 Replies)
Discussion started by: emdeex
0 Replies

9. Programming

C++ Input File line by line

Hi there, I need to read some data from a file with string and number that is similar to this: word1 0.0 1.0 0.0 word3 word4 0.0 0.0 -1.0 word1 0.0 0.0 1.0 word5With this code: #include<iostream> #include<fstream> #include<string> using namespace std; int main() ... (5 Replies)
Discussion started by: Giordano Bruno
5 Replies

10. How to Post in the The UNIX and Linux Forums

Read a json file passed as cmd line argument

usage: myscript.sh config.json config.json: { "HOST":"abc", "DB_NM":"xyz", "USR_NM":"asd", "PWD":"xxx", ......... ......... ......... ........ } myscript.sh: (2 Replies)
Discussion started by: RGRT
2 Replies
STDIO(3)						     Linux Programmer's Manual							  STDIO(3)

NAME
stdio - standard input/output library functions SYNOPSIS
#include <stdio.h> FILE *stdin; FILE *stdout; FILE *stderr; DESCRIPTION
The standard I/O library provides a simple and efficient buffered stream I/O interface. Input and output is mapped into logical data streams and the physical I/O characteristics are concealed. The functions and macros are listed below; more information is available from the individual man pages. A stream is associated with an external file (which may be a physical device) by opening a file, which may involve creating a new file. Creating an existing file causes its former contents to be discarded. If a file can support positioning requests (such as a disk file, as opposed to a terminal) then a file position indicator associated with the stream is positioned at the start of the file (byte zero), unless the file is opened with append mode. If append mode is used, it is unspecified whether the position indicator will be placed at the start or the end of the file. The position indicator is maintained by subsequent reads, writes and positioning requests. All input occurs as if the characters were read by successive calls to the fgetc(3) function; all output takes place as if all characters were written by succes- sive calls to the fputc(3) function. A file is disassociated from a stream by closing the file. Output streams are flushed (any unwritten buffer contents are transferred to the host environment) before the stream is disassociated from the file. The value of a pointer to a FILE object is indeterminate after a file is closed (garbage). A file may be subsequently reopened, by the same or another program execution, and its contents reclaimed or modified (if it can be reposi- tioned at the start). If the main function returns to its original caller, or the exit(3) function is called, all open files are closed (hence all output streams are flushed) before program termination. Other methods of program termination, such as abort(3) do not bother about closing files properly. At program startup, three text streams are predefined and need not be opened explicitly -- standard input (for reading conventional input), -- standard output (for writing conventional input), and standard error (for writing diagnostic output). These streams are abbreviated stdin,stdout and stderr. When opened, the standard error stream is not fully buffered; the standard input and output streams are fully buffered if and only if the streams do not to refer to an interactive device. Output streams that refer to terminal devices are always line buffered by default; pending output to such streams is written automatically whenever an input stream that refers to a terminal device is read. In cases where a large amount of computation is done after printing part of a line on an output terminal, it is necessary to fflush(3) the standard output before going off and computing so that the output will appear. The stdio library is a part of the library libc and routines are automatically loaded as needed by the compilers cc(1) and pc(1). The SYN- OPSIS sections of the following manual pages indicate which include files are to be used, what the compiler declaration for the function looks like and which external variables are of interest. The following are defined as macros; these names may not be reused without first removing their current definitions with #undef: BUFSIZ, EOF, FILENAME_MAX, FOPEN_MAX, L_cuserid, L_ctermid, L_tmpnam, NULL, SEEK_END, SEEK_SET, SEEK_CUR, TMP_MAX, clearerr, feof, ferror, fileno, getc, getchar, putc, putchar, stderr, stdin, stdout. Function versions of the macro functions feof, ferror, clearerr, fileno, getc, getchar, putc, and putchar exist and will be used if the macros definitions are explicitly removed. List of Functions Function Description ------------------------------------------------------------------- clearerr check and reset stream status fclose close a stream fdopen stream open functions feof check and reset stream status ferror check and reset stream status fflush flush a stream fgetc get next character or word from input stream fgetpos reposition a stream fgets get a line from a stream fileno return the integer descriptor of the argument stream fopen stream open functions fprintf formatted output conversion fpurge flush a stream fputc output a character or word to a stream fputs output a line to a stream fread binary stream input/output freopen stream open functions fscanf input format conversion fseek reposition a stream fsetpos reposition a stream ftell reposition a stream fwrite binary stream input/output getc get next character or word from input stream getchar get next character or word from input stream gets get a line from a stream getw get next character or word from input stream mktemp make temporary filename (unique) perror system error messages printf formatted output conversion putc output a character or word to a stream putchar output a character or word to a stream puts output a line to a stream putw output a character or word to a stream remove remove directory entry rewind reposition a stream scanf input format conversion setbuf stream buffering operations setbuffer stream buffering operations setlinebuf stream buffering operations setvbuf stream buffering operations sprintf formatted output conversion sscanf input format conversion strerror system error messages sys_errlist system error messages sys_nerr system error messages tempnam temporary file routines tmpfile temporary file routines tmpnam temporary file routines ungetc un-get character from input stream vfprintf formatted output conversion vfscanf input format conversion vprintf formatted output conversion vscanf input format conversion vsprintf formatted output conversion vsscanf input format conversion CONFORMING TO
The stdio library conforms to C89. SEE ALSO
close(2), open(2), read(2), write(2), stdout(3), unlocked_stdio(3) COLOPHON
This page is part of release 3.27 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. 2001-12-26 STDIO(3)
All times are GMT -4. The time now is 07:57 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy