Sponsored Content
Top Forums Programming Storing the output of a Unix cmd in my C program Post 302436449 by Goseib on Monday 12th of July 2010 04:01:20 AM
Old 07-12-2010
Storing the output of a Unix cmd in my C program

Hello experts,


How can I retrieve the output from a Unix command and use it as string variable in my C program?
For example, when I issue the command 'date' I get:
Tue Jun 11 09:54:16 EEST 2009


I do not want to redirect the output of the command to a file and then open the file from my C program and then read the string.



Is there any other way?



Thank you in advance,
G.
 

10 More Discussions You Might Find Interesting

1. Programming

storing date into a file from a program

hi all: i want to store the current date in to a file from a program. every time i execute the prg the date should get appended into the file. help me plz (2 Replies)
Discussion started by: bankpro
2 Replies

2. Shell Programming and Scripting

storing output of awk in variable

HI I am trying to store the output of this awk command awk -F, {(if NR==2) print $1} test.sr in a variable when I am trying v= awk -F, {(if NR==2) print $1} test.sr $v = awk -F, {(if NR==2) print $1} test.sr but its not working out . Any suggestions Thanks Arif (3 Replies)
Discussion started by: mab_arif16
3 Replies

3. UNIX for Dummies Questions & Answers

Storing the output into a variable

Hi unix gurus, I am trying to store the result of a command into a variable. But it is not getting stored. x='hello' y=echo $x | wc -c but it is giving the output as 0(zero) Pls help me its very urgent (7 Replies)
Discussion started by: ravi raj kumar
7 Replies

4. Shell Programming and Scripting

Storing awk output into variables

Hi all, Currently, i have a log file seperated by 'tab' and each record starting with a new line. i managed to retrieve the column that i'm interested in. (source_ip_address: xxx.xxx.xxx.xxx). example of awk output: '{ print $43 }' assuming the field is at column 43. 10.10.10.10... (4 Replies)
Discussion started by: faelric
4 Replies

5. Shell Programming and Scripting

Problem with `cat` the compiled output of C program in unix

Hello All, I have coded a C program which looks something like below... (program name: test.c) #include<stdio.h> main() { int dist,dm,dcm; printf(" Enter the distance between 2 cities in KM : "); scanf("%d",&dist); dm=dist*1000; dcm=dist*10; printf("Distance between 2 cities in... (6 Replies)
Discussion started by: smarty86
6 Replies

6. Programming

popen hangs program during cmd execution

How can I get around this? when my program reaches the following popen job it halts the program until the ping/netstat/ipconfig/traceroute is completed then resume to the rest of the program... FILE *in; extern FILE *popen(); char buff; char newline; char nstat; char nping; ... (5 Replies)
Discussion started by: Jess83
5 Replies

7. Shell Programming and Scripting

Unix cmd prompt how to get old cmd run?

Hi, I am using SunOS I want to serch my previous command from unix prompt (like on AIX we can search by ESC -k) how to get in SunOs urgent help require. (10 Replies)
Discussion started by: RahulJoshi
10 Replies

8. Shell Programming and Scripting

Storing or Using Numeric Output From a Function

Hi all, I'm trying to implement a linear congruential pseudorandom number generator (<http://en.wikipedia.org/wiki/Linear_congruential_generator>), since $RANDOM and /dev/random aren't standardized. I'm referring to the Shell & Utilities volume of POSIX.1-2008, but I'm running into some odd... (3 Replies)
Discussion started by: PehJota
3 Replies

9. Shell Programming and Scripting

Storing output into a variable

My script below seems to be choking because I need the the output of the find command to be stored as a variable that can then be called by used lower in the script. #!/bin/bash cd "/resumes_to_be_completed" var1=find . -mmin -1 -type f \( -name "*.doc" -o -name "*.docx" \)... (1 Reply)
Discussion started by: binary-ninja
1 Replies

10. Shell Programming and Scripting

Storing command output in an array

Hi, I want keep/save one command's output in an array and later want to iterate over the array one by one for some processing. instead of doing like below- for str in `cat /etc/passwd | awk -F: '$3 >100 {print $1}' | uniq` want to store- my_array = `cat /etc/passwd | awk -F: '$3 >100 {print... (4 Replies)
Discussion started by: sanzee007
4 Replies
GREPHISTORY(1)						    InterNetNews Documentation						    GREPHISTORY(1)

NAME
grephistory - Query the INN history database SYNOPSIS
grephistory [-eilnqsv] [-f db] [message-id] DESCRIPTION
grephistory queries the INN history database for information about the specified message-ID. If no flags are given, the program prints the storage API token of the corresponding article, or "/dev/null" if the article is listed in the history database but not stored on the server. If the message-ID cannot be found in the database, grephistory will print "grephistory: not found" and exit with a non-zero status. Be sure to escape any special characters in the message ID from the shell. Single quotes are recommended for this purpose since many message-IDs contain dollar signs. OPTIONS
-e Only print the storage token if the article is stored on the system. (In other words, suppress the "/dev/null" or "not found" output for missing or remembered articles.) -f db Query the history database db rather than the default history database. -i Rather than expecting a message-ID on the command line, grephistory will read a list of message-IDs on standard input, one per line. Leading and trailing whitespace is ignored, as are any malformed lines. It will print on standard output those message-IDs which are not found in the history database. This is used when processing "ihave" control messages. -l Display the entire line from the history database, rather than just the storage API token. If the message-ID is present in the history database but has no storage API token, grephistory does not print anything. -n If the message-ID is present in the history database but has no storage API token, print "/dev/null" and exit successfully. This can happen if an article has been cancelled or expired, but history information has still been retained. This is the default behavior. -q Don't print any message, but still exit with the appropriate status. -s Rather than expecting a message-ID on the command line, grephistory will read a list of message-IDs on standard input, one per line. Leading and trailing whitespace is ignored, as are any malformed lines. It will print on standard output the storage API tokens for any articles that are still available, one per line. This flag is used when processing "sendme" control messages. -v Print out the hash of the message-ID for diagnostic purposes, as well as any other requested information. This flag is not useful with -i or -s. EXAMPLES
In case the requested article is not listed in the history database: % grephistory '<unknown.article@news.example.com>' grephistory: not found % grephistory -v '<unknown.article@news.example.com>' grephistory: not found (hash is 501C66C22932BA91131186D7218201EB) In case the requested article is listed in the history database but not stored on the server: % grephistory '<remembered.article@news.example.com>' /dev/null In case the requested article is stored on the server: % grephistory '<87fxeaay1z.fsf@windlord.stanford.edu>' @02014A2DD6231FCC00000000000000000000@ % grephistory -l '<87fxeaay1z.fsf@windlord.stanford.edu>' [B6DDF69376E3CC199246CEC949B3ACAC] 1244517923~-~1244517912 @02014A2DD6231FCC00000000000000000000@ With sm, we can retrieve the article, and get its posting date: % grephistory '<87fxeaay1z.fsf@windlord.stanford.edu>' | sm | grep Date Date: Mon, 08 Jun 2009 20:25:12 -0700 % convdate -dc 1244517912 Tue, 9 Jun 2009 03:25:12 +0000 (UTC) It matches the number recorded in history as for its posting date. HISTORY
Written by Rich $alz <rsalz@uunet.uu.net> for InterNetNews. Rewritten in POD by Russ Allbery <rra@stanford.edu>. $Id: grephistory.pod 8582 2009-08-19 08:04:32Z iulius $ SEE ALSO
history(5), inn.conf(5), sm(1). INN 2.5.2 2009-09-11 GREPHISTORY(1)
All times are GMT -4. The time now is 05:39 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy