nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

How to Redirect OutPut of Shell Command to a text file

This is a discussion on How to Redirect OutPut of Shell Command to a text file within the Shell scripting forums, part of the Development/Scripting category; Hi, I m working on Solaris 10 and want to redirect the output of the command to text file using ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 28-04-2009, 10:26 AM
Junior Member
User
 
Join Date: Apr 2009
OS: Quaidian
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
Hadi is on a distinguished road
Default How to Redirect OutPut of Shell Command to a text file

Hi, I m working on Solaris 10 and want to redirect the output of the command to text file using C++

I wanna to write prstat command to file using c++

main()
{
System("prstat -t > fileName.txt");
}

but it does not work.. Kindly help me

Regards:
Hadi
Reply With Quote
  #2 (permalink)  
Old 29-04-2009, 07:27 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 244 Times in 183 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Try the following format:
Code:
command  &>/path/to/logfile
command > /path/to/logfile 2>&1
Another option - write code as follows:
Code:
main()
{
         System("prstat -t ");
}
And run it as follows:
Code:
./a.out > output.txt
./a.out &>output.txt
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help

Last edited by nixcraft; 29-04-2009 at 07:31 PM.
Reply With Quote
Reply

Tags
c++ , c++ redirect output , g++ , shell redirect output , solaris , unix


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
print a "FTP dir command" output into a .txt file ecompean Shell scripting 2 09-02-2009 11:34 PM
how to display text when no output is available sidebrake Shell scripting 3 29-10-2008 12:44 PM
text output to mysql chebbab Shell scripting 4 26-11-2007 07:29 PM
How to redirect Output puppen Shell scripting 15 06-12-2006 08:44 PM
How can I redirect the output of time command to file warren Linux software 13 25-08-2006 11:17 AM


All times are GMT +5.5. The time now is 02:17 AM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38