Sponsored Content
Top Forums Shell Programming and Scripting How to capture system() function output in variable Post 302911427 by Perderabo on Thursday 31st of July 2014 02:23:18 PM
Old 07-31-2014
Quote:
Originally Posted by bharat1211
Ha soo we cannot capture commands
Soo there is no way to capture result? ????SmilieSmilieSmilieSmilie
See this thread.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[csh] How to capture output from a command and pass it on to a variable?

Hi there! I'm trying to write a script that will capture output from a command and assign it to a variable. Let's say, for example, I'd like to catch from inside the script whatever the following command outputs: ls *.aaa and put it into a variable "listoffiles". What I tried was: set... (3 Replies)
Discussion started by: machinogodzilla
3 Replies

2. Shell Programming and Scripting

Passing global variable to a function which is called by another function

Hi , I have three funcions f1, f2 and f3 . f1 calls f2 and f2 calls f3 . I have a global variable "period" which i want to pass to f3 . Can i pass the variable directly in the definition of f3 ? Pls help . sars (4 Replies)
Discussion started by: sars
4 Replies

3. Shell Programming and Scripting

how to capture oracle function returning 2 values in unix

i have an oracle function which returns two values, one is the error message if the function encounters anything and another one which returns a number i need to capture both and pass it on to unix shell script how to do it (2 Replies)
Discussion started by: trichyselva
2 Replies

4. Programming

[C language] system function print output when not expected.

Hi, I am new to C and have a little problem. I am not planning to be a C expert, but this would be nice to understand. The problem is that a 'system' call prints it output to stdout, when I do not expect this. This is the program: trial.c #include <ctype.h> #include <unistd.h>... (5 Replies)
Discussion started by: ejdv
5 Replies

5. Shell Programming and Scripting

unix capture oracle function error

Hi, I want to execute an oracle function from unix script so for that I created a sample oracle function as below: create or replace function test_fn(test_date out varchar2) RETURN varchar2 IS BEGIN select to_char(sysdate,'DD-MON-YY') into test_date from dual; return test_date;... (5 Replies)
Discussion started by: dips_ag
5 Replies

6. Programming

capture the output of printf into another variable

Hi , I wonder if in java I can pipe the below output of the printf into a variable: System.out.printf(" This is a test %s\n", myVariable); I want to keep the output of the printf command to create my history array. Thanks. (2 Replies)
Discussion started by: arizah
2 Replies

7. Shell Programming and Scripting

System Output in to an Array or variable

hey guys in only new to scripting as such, but i have a problem. i want to take the output of a search i do in the command line to then be in a variable but only a certain part of the output. this this what im doing: -bash-2.05b$ ldapsearch -x '(dn:=dc)' dc|grep dc= # base... (1 Reply)
Discussion started by: jmorey
1 Replies

8. UNIX for Dummies Questions & Answers

Capture Multiple Lines Into Variable As Of Standard Output

Hello All, I have the below script and output. cat test.sh #!/bin/bash -x logit() { echo " - ${*}" > ${LOG_FILE} } LOG_FILE=/home/infrmtca/bin/findtest.log VAR=`find . -type f -name "*sql"` logit $VAR Output: cat /home/infrmtca/bin/findtest.log -... (9 Replies)
Discussion started by: Ariean
9 Replies

9. Homework & Coursework Questions

How to Dynamically Pass Parameter to plsql Function & Capture its Output Value in a Shell Variable?

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: 2. Relevant commands, code, scripts, algorithms: #! /bin/ksh v="ORG_ID" ... (2 Replies)
Discussion started by: sujitdas2104
2 Replies

10. Red Hat

Unable to capture value from function

Hi Experts, Am writing a code which need to check for the previous day date and pickup the file as per the previous day date. Problem: Why variable "YDATE" is empty ? O/S: RHEL 5.6 Shell: BASH Desired O/P: ls -lrt /opt/test/user/atsuser.NHU/out/demon.08272017 When I checked the... (3 Replies)
Discussion started by: pradeep84in
3 Replies
IO::Capture::Stdout(3pm)				User Contributed Perl Documentation				  IO::Capture::Stdout(3pm)

NAME
IO::Capture::Stdout - Capture any output sent to STDOUT SYNOPSIS
# Generic example (Just to give the overall view) use IO::Capture::Stdout; $capture = IO::Capture::Stdout->new(); $capture->start(); # STDOUT Output captured print STDOUT "Test Line One "; print STDOUT "Test Line Two "; print STDOUT "Test Line Three "; $capture->stop(); # STDOUT output sent to wherever it was before 'start' # In 'scalar context' returns next line $line = $capture->read; print "$line"; # prints "Test Line One" $line = $capture->read; print "$line"; # prints "Test Line Two" # move line pointer to line 1 $capture->line_pointer(1); $line = $capture->read; print "$line"; # prints "Test Line One" # Find out current line number $current_line_position = $capture->line_pointer; # In 'List Context' return an array(list) @all_lines = $capture->read; # More useful example 1 - "Using in module tests" # Note: If you don't want to make users install # the IO::Capture module just for your tests, # you can just install in the t/lib directory # of your module and use the lib pragma in # your tests. use lib "t/lib"; use IO::Capture::Stdout; use Test::More; my $capture = IO::Capture::Stdout->new; $capture->start # execute with a bad parameter to make sure get # an error. ok( ! $test("Bad Parameter") ); $capture->stop(); DESCRIPTION
The module "IO::Capture::Stdout", is derived from the abstract class "IO::Capture". See IO::Capture. The purpose of the module (as the name suggests) is to capture any output sent to "STDOUT". After the capture is stopped, the STDOUT filehandle will be reset to the previ- ous location. E.g., If previously redirected to a file, when "IO::Capture->stop" is called, output will start going into that file again. Note: This module won't work with the perl function, system(), or any other operation involving a fork(). If you want to capture the output from a system command, it is faster to use open() or back-ticks. my $output = `/usr/sbin/ls -l 2>&1`; METHODS
new o Creates a new capture object. o An object can be reused as needed, so will only need to do one of these. o Be aware, any data previously captured will be discarded if a new capture session is started. start o Start capturing data into the "IO::Capture" Object. o Can not be called on an object that is already capturing. o Can not be called while STDOUT tied to an object. o "undef" will be returned on an error. stop o Stop capturing data and point STDOUT back to it's previous output location I.e., untie STDOUT read o In Scalar Context o Lines are read from the buffer at the position of the "line_pointer", and the pointer is incremented by one. $next_line = $capture->read; o In List Context o The array is returned. The "line_pointer" is not affected. @buffer = $capture->read; o Data lines are returned exactly as they were captured. You may want to use "chomp" on them if you don't want the end of line charac- ter(s) while (my $line = $capture->read) { chomp $line; $cat_line = join '', $cat_line, $line; } line_pointer o Reads or sets the "line_pointer". my $current_line = $capture->line_pointer; $capture->line_pointer(1); SUB-CLASSING Adding Features If you would like to sub-class this module to add a feature (method) or two, here is a couple of easy steps. Also see IO::Capture::Over- view. 1 Give your package a name package MyPackage; 2 Use this "IO::Capture::Stdout" as your base class like this: package MyPackage; use base qw/IO::Capture::Stdout/; 3 Add your new method like this package MyPackage; use base qw/IO::Capture::Stdout/; sub grep { my $self = shift; for $line ( } See Also IO::Capture::Overview IO::Capture IO::Capture::Stderr AUTHORS
Mark Reynolds reynolds@sgi.com Jon Morgan jmorgan@sgi.com COPYRIGHT
Copyright (c) 2003, Mark Reynolds. All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself. perl v5.8.8 2007-07-30 IO::Capture::Stdout(3pm)
All times are GMT -4. The time now is 07:30 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy