Sponsored Content
Full Discussion: stdin redirection
Top Forums UNIX for Dummies Questions & Answers stdin redirection Post 302401166 by jlliagre on Friday 5th of March 2010 04:57:56 AM
Old 03-05-2010
Use fopen and fscanf instead.
 

10 More Discussions You Might Find Interesting

1. Programming

Changing stdin from file redirection to console input

Hi I am doing file redirection at console for use by my binary. %console%> bin &lt inputfile After reading in the entire file, I want my program to continue taking input from the console. So essentially I want to redirect stdin back to console. But I cant figure out how to do it. I am... (4 Replies)
Discussion started by: nauman
4 Replies

2. Programming

stdin

hi, how does a program know whether some data are available from stdin? I would like to make a program which could read its data from stdin and _if_there_is_nothing_at_stdin_ from a file which name is given as an argument. If there is nothing in stdin and no filename is given as argument,... (2 Replies)
Discussion started by: marquis
2 Replies

3. HP-UX

stdin device on HP

How can I access the standard-in device in HP-UX? I am trying to automate sftp on an HP-UX system. On solaris I can just do: sftp -b /dev/fd/0 remotehost <<EOF cd pub ascii get filename.txt bye EOF (2 Replies)
Discussion started by: dangral
2 Replies

4. Shell Programming and Scripting

redirection stdin

hello all, I need to create a password change utility for a database. I need to gather at the command line the username, password and database sid. I have the program currently doing this. What I would like to do is not have the new password appear on the screen when I do my read command.... (2 Replies)
Discussion started by: whited05
2 Replies

5. Shell Programming and Scripting

redirect STDIN

can you redirect STDIN with command arguments? I have tried this approach: # ./script -option <argument1> <argument2> 0<$2 # $2: ambiguous redirect Is this possible? (4 Replies)
Discussion started by: prkfriryce
4 Replies

6. Programming

How to write to stdin of another program (program A -> [stdin]program B)

Hi, Program A: uses pipe() I am able to read the stdout of PROGAM B (stdout got through system() command) into PROGRAM A using: * child -> dup2(fd, STDOUT_FILENO); -> execl("/path/PROGRAM B", "PROGRAM B", NULL); * parent -> char line; -> read(fd, line, 100); Question: ---------... (1 Reply)
Discussion started by: vvaidyan
1 Replies

7. UNIX for Dummies Questions & Answers

How to write to stdin of another program (program A -> [stdin]program B)

Hi, Program A: uses pipe() I am able to read the stdout of PROGAM B (stdout got through system() command) into PROGRAM A using: * child -> dup2(fd, STDOUT_FILENO); -> execl("/path/PROGRAM B", "PROGRAM B", NULL); * parent -> char line; -> read(fd, line, 100); Question: ---------... (3 Replies)
Discussion started by: vvaidyan
3 Replies

8. UNIX for Dummies Questions & Answers

fork and stdin

When a process fork(), the child share the same file descriptors as his father. Thus, they share the same stdin. Quick and dirty exemple below (sorry for the ugly gets() call) : #include <stdio.h> #include <unistd.h> int main() { char buf; if (fork()) { /*parent */ ... (1 Reply)
Discussion started by: milouz
1 Replies

9. Shell Programming and Scripting

Redirecting stdin from fd 3-9?

Hi I'm trying to do something on the bash command line that I will later put into a bash shell script. I'm trying to take a program that reads stdin (using getline) and be able to keep it running in the background and fire "commands" to it. So what I thought I should do was to try taking... (3 Replies)
Discussion started by: niceguyeddie
3 Replies

10. UNIX for Dummies Questions & Answers

redirection stdin

Bonjour, Mon application en C sous linux tourne en redirigeant stdin vers un fichier. Exemple; $appli1 <file1. PB: Je voudrais temporairement redonner la main au user sur le clavier. Alors je pensais ajouter system("appli2"); dans appli1. Dans son main() , appli2() fait seulement un... (1 Reply)
Discussion started by: cypleen
1 Replies
FREAD(3)								 1								  FREAD(3)

fread - Binary-safe file read

SYNOPSIS
string fread (resource $handle, int $length) DESCRIPTION
fread(3) reads up to $length bytes from the file pointer referenced by $handle. Reading stops as soon as one of the following conditions is met: o$length bytes have been read o EOF (end of file) is reached o a packet becomes available or the socket timeout occurs (for network streams) o if the stream is read buffered and it does not represent a plain file, at most one read of up to a number of bytes equal to the chunk size (usually 8192) is made; depending on the previously buffered data, the size of the returned data may be larger than the chunk size. PARAMETERS
o $handle -A file system pointer resource that is typically created using fopen(3). o $length - Up to $length number of bytes read. RETURN VALUES
Returns the read string or FALSE on failure. EXAMPLES
Example #1 A simple fread(3) example <?php // get contents of a file into a string $filename = "/usr/local/something.txt"; $handle = fopen($filename, "r"); $contents = fread($handle, filesize($filename)); fclose($handle); ?> Example #2 Binary fread(3) example Warning On systems which differentiate between binary and text files (i.e. Windows) the file must be opened with 'b' included in fopen(3) mode parameter. <?php $filename = "c:\files\somepic.gif"; $handle = fopen($filename, "rb"); $contents = fread($handle, filesize($filename)); fclose($handle); ?> Example #3 Remote fread(3) examples Warning When reading from anything that is not a regular local file, such as streams returned when reading remote files or from popen(3) and fsockopen(3), reading will stop after a packet is available. This means that you should collect the data together in chunks as shown in the examples below. <?php // For PHP 5 and up $handle = fopen("http://www.example.com/", "rb"); $contents = stream_get_contents($handle); fclose($handle); ?> <?php $handle = fopen("http://www.example.com/", "rb"); if (FALSE === $handle) { exit("Failed to open stream to URL"); } $contents = ''; while (!feof($handle)) { $contents .= fread($handle, 8192); } fclose($handle); ?> NOTES
Note If you just want to get the contents of a file into a string, use file_get_contents(3) as it has much better performance than the code above. Note Note that fread(3) reads from the current position of the file pointer. Use ftell(3) to find the current position of the pointer and rewind(3) to rewind the pointer position. SEE ALSO
fwrite(3), fopen(3), fsockopen(3), popen(3), fgets(3), fgetss(3), fscanf(3), file(3), fpassthru(3), ftell(3), rewind(3). PHP Documentation Group FREAD(3)
All times are GMT -4. The time now is 05:46 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy