Sponsored Content
Top Forums UNIX for Advanced & Expert Users Help with command substitution in C program Post 302463525 by royalbull on Sunday 17th of October 2010 10:43:01 PM
Old 10-17-2010
Yes i am aware of popen , but something else which mimics exactly command-substitution (``) of shell ?? How is it achieved in shell ??
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Substitution of last command

"Is there any substituation of last command or script syntax which can be used as a user. As far I know the "last" command is being used to display information about previous logins. A member of adm group or the user adm can execute it only. Thanks in advance for your usual help. Ghazi (6 Replies)
Discussion started by: ghazi
6 Replies

2. UNIX for Dummies Questions & Answers

Script to open program and send/execute command in program

Hi, i want to write a script that executes a program (exec?) . this program then requires a filename as input. how do i give it this input in the script so the program will be complete run and close by the script. e.g. exec prog.exe program then asks for filename "enter filename:"... (1 Reply)
Discussion started by: tuathan
1 Replies

3. Shell Programming and Scripting

Difference between "Command substitution" and "Process substitution"

Hi, What is the actual difference between these two? Why the following code works for process substitution and fails for command substitution? while IFS= read -r line; do echo $line; done < <(cat file)executes successfully and display the contents of the file But, while IFS='\n' read -r... (3 Replies)
Discussion started by: royalibrahim
3 Replies

4. Shell Programming and Scripting

Can process substitution be used as an input file to another program?

Hey, I was trying to figure out how to launch a program from the command line, and it works if you pass it a config file. I was thinking about writing a script to dynamically create the config file and pass it to the command using something like command substitution (so I don't actually have to... (3 Replies)
Discussion started by: bj0
3 Replies

5. UNIX for Dummies Questions & Answers

sed insert command and variable expansion/command substitution

I know this script is crummy, but I was just messing around.. how do I get sed's insert command to allow variable expansion to show the filename? #!/bin/bash filename=`echo $0` /usr/bin/sed '/#include/ { i\ the filename is `$filename` }' $1 exit 0 (8 Replies)
Discussion started by: glev2005
8 Replies

6. UNIX for Dummies Questions & Answers

read command - using output from command substitution

Hey, guys! Trying to research this is such a pain since the read command itself is a common word. Try searching "unix OR linux read command examples" or using the command substitution keyword. :eek: So, I wanted to use a command statement similar to the following. This is kinda taken... (2 Replies)
Discussion started by: ProGrammar
2 Replies

7. Shell Programming and Scripting

command substitution doubt

Hi, I almost always use back quotes in scripts to assigin output of a command to a variable. eg: file=`basename a/b/c/d/file` year_mon=`date +%Y%m` But the same can be achieved like: file=$(basename a/b/c/d/file) year_mon=$(date +%Y%m) I would like to know if there is... (3 Replies)
Discussion started by: wanderingmind16
3 Replies

8. Shell Programming and Scripting

Substitution within string command

I have the following code: strfuture=abcdefghi ver=${strfuture:${count}:1} mj7777_ver=${ver} start_mj7777_iteration let count=count+1 When it is executed I get bad substitution. The same if I use ver=${strfuture:$count:1} mj7777_ver=${ver}... (6 Replies)
Discussion started by: Bruble
6 Replies

9. Shell Programming and Scripting

Regarding command substitution

Oracle Linux 5.6, 64-bit Given the following snippet wrkvar=`sqlplus -s / as sysdba <<EOF set echo off feedback off head off trimsp on select count(*) from v\$parameter where name in ('db_file_name_convert','log_file_name_convert') and value is not null; EOF` echo wrkvar=$wrkvarProduces... (2 Replies)
Discussion started by: edstevens
2 Replies

10. Shell Programming and Scripting

Command option substitution?

Hi folks, I totally dislike asking questions in forums but this one eats up to much of my time I need to spend on other topics. I have a shell-script in which I call a terminal. I want to invoke bash inside the terminal and print a message inside bash with aid of a here document. See... (7 Replies)
Discussion started by: bluntroller
7 Replies
popen(3)						     Library Functions Manual							  popen(3)

NAME
popen - Initiates a pipe to a process LIBRARY
Standard C Library (libc.so, libc.a) SYNOPSIS
#include <stdio.h> FILE *popen ( const char *command, const char *type ); STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: popen(): XPG4, XPG4-UNIX Refer to the standards(5) reference page for more information about industry standards and associated tags. PARAMETERS
Points to a null-terminated string containing a shell command line. Points to a null-terminated string containing an I/O mode. DESCRIPTION
The popen() function creates a pipe between the calling program and a shell command to be executed. It returns a pointer to a FILE struc- ture for the stream. If the type parameter is the value r, the calling program can read from the standard output of the command by reading from the returned file stream. If the type parameter is the value w, the calling program can write to the standard input of the command by writing to the returned file stream. Because open files are shared, a type r command can be used as an input filter and a type w command as an output filter. NOTES
Programs using the popen() function to invoke an output filter should beware of possible deadlock caused by output data remaining in the program's buffer. This can be avoided by either using the setbuf() function to ensure that the output stream is unbuffered, or by using the fflush() function to ensure that all buffered data is flushed before calling the pclose() function. If the original processes and the process started with the popen() function concurrently read or write a common file, neither should use buffered I/O. If they do, the results are unpredictable. RETURN VALUES
Upon successful completion, the popen() function returns a pointer to the FILE structure for the opened stream. In case of error because files or processes could not be created, the popen() function returns a null pointer. RELATED INFORMATION
Functions: exec(2), fork(2), fclose(3), fopen(3), pclose(3), pipe(2), setbuf(3) Standards: standards(5) delim off popen(3)
All times are GMT -4. The time now is 04:45 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy