Sponsored Content
Top Forums Programming [C language] system function print output when not expected. Post 302418492 by Corona688 on Tuesday 4th of May 2010 12:10:14 PM
Old 05-04-2010
Quote:
Originally Posted by ejdv
Thanks.

That explained why I did not see the return values.
But the command output is still printed.
Yes, it prints to standard output and standard error. When you create a new process it gets copies of your file descriptors.
Quote:
As I have control over the exit value of the command executed, I can have the output go to "> /dev/null 2&>1".
Then with "WEXITSTATUS" I can parse the exit value to my variable.

Slowly getting there :-)
Sure you can. But if that output's the thing you wanted to get, then you're not accomplishing much. Smilie By using system() you're executing a whole new shell and running things inside it. Handy sometimes but if you want to program C, not the way things are generally done.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk not generating the expected output

Hi, I am presently stuck in a csv file. INPUT CSV baseball,NULL,8798765,Most played baseball,NULL,8928192,Most played baseball,NULL,5678945,Most played cricket,NOTNULL,125782,Usually played cricket,NOTNULL,678921,Usually played EXPECTED OUTPUT CSV ... (7 Replies)
Discussion started by: scripter12
7 Replies

2. Shell Programming and Scripting

Print records which do not have expected number of fields in a comma delimited file

Hi, I have a comma (,) delimited file, in which few fields are enclosed with in double quotes " ". I have to print the records in the file which donot have expected number of field with the line number. File1 ==== name,desgnation,doj,project #header#... (7 Replies)
Discussion started by: machomaddy
7 Replies

3. Shell Programming and Scripting

Output is not comming as expected

Hi All, I am in middle of one script. I want output in the form of xls file. There are 4 fields - user name, email Id, full name, date of birth. I want these details to get in seperate columns. But, i am getting it in the single cell and as like a paragraph.:mad: Please suggest me some... (8 Replies)
Discussion started by: Agupte
8 Replies

4. Shell Programming and Scripting

Not getting expected output

Hi I have written below script to get the data in table form. #!/bin/sh echo "File Name\tType" for i in *; do echo "$i\t\c" if ; then echo "directory" elif ; then echo "symbolic link" elif ; then echo "file" else echo "unknown" fi donehowever i am getting output in different way... (3 Replies)
Discussion started by: scriptor
3 Replies

5. Shell Programming and Scripting

Grep can't match expected but output all

lyang001@lyang001-OptiPlex-9010:~$ service --status-all |grep dbus acpid acpi-support alsa-restore alsa-store anacron apport atd avahi-daemon bluetooth cgroup-lite console-setup cron cups dbus dmesg dns-clean failsafe-x ... (1 Reply)
Discussion started by: yanglei_fage
1 Replies

6. Shell Programming and Scripting

How to capture system() function output in variable

How to capture system() function output in awk variable and the print that awk variable..... (8 Replies)
Discussion started by: bharat1211
8 Replies

7. Shell Programming and Scripting

awk output not what was expected

Good Moring, I am currently reading about awk in a manual and following the examples using the oratab file. My system is SOLARIS 10 I think I am getting strange behavior judging by what the book says to do and what I am getting with my little program. Here is my program: grep -v oratab |... (4 Replies)
Discussion started by: bdby
4 Replies

8. Shell Programming and Scripting

For loop not giving expected output

#cat /tmp/input old_array old_dev new_dev new_array 0577 008AB 01744 0125 0577 008AC 01745 0125 0577 008AD 005C8 0125 0577 008AE 005C9 0125 0577 008AF 005CA 0125 0577 008B0 005CB 0125 0577 008B1 005CC 0125 cat test.sh #!/bin/ksh... (4 Replies)
Discussion started by: mbak
4 Replies

9. Shell Programming and Scripting

awk not giving the output expected

Hello, I am practising awk and decided to compare two columns and print the result of the comparison as third column i/p data c1,c2,c3 1,a,b 1,b,b i am trying to compare the last two columns and if they match I am trying to print match else mismatch(Ideally i want that as a last column... (5 Replies)
Discussion started by: mkathi
5 Replies
App::Cmd::Tester::CaptureExternal(3pm)			User Contributed Perl Documentation		    App::Cmd::Tester::CaptureExternal(3pm)

NAME
App::Cmd::Tester::CaptureExternal - Extends App::Cmd::Tester to capture from external subprograms VERSION
version 0.318 SYNOPSIS
use Test::More tests => 4; use App::Cmd::Tester::CaptureExternal; use YourApp; my $result = test_app(YourApp => [ qw(command --opt value) ]); like($result->stdout, qr/expected output/, 'printed what we expected'); is($result->stderr, '', 'nothing sent to sderr'); ok($result->output, "STDOUT concatenated with STDERR"); DESCRIPTION
App::Cmd::Tester provides a useful scaffold for testing applications, but it is unable to capture output generated from any external subprograms that are invoked from the application. This subclass uses an alternate mechanism for capturing output (Capture::Tiny) that does capture from external programs, with one major limitation. It is not possible to capture externally from both STDOUT and STDERR while also having appropriately interleaved combined output. Therefore, the "output" from this subclass simply concatenates the two. You can still use "output" for testing if there is any output at all or for testing if something appeared in either output stream, but you can't rely on the ordering being correct between lines to STDOUT and lines to STDERR. AUTHOR
Ricardo Signes <rjbs@cpan.org> COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Ricardo Signes. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.14.2 2012-05-05 App::Cmd::Tester::CaptureExternal(3pm)
All times are GMT -4. The time now is 05:13 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy