Save output in a variable

Hi,
I have a 3rd party tool on Solaris 8. I am running it thorugh my script but I am not able to capture its output into a variable.

Like, I tried, but did not work.

output=`/usr/bin/myTool`
echo $output

Also, I tried saving in a file but when I run, output is always shown on the comsole.

`/usr/bin/myTool` > output.txt

Please let me know how do I capture in a variable.

Maybe that tool prints it's STDOUT stuff to STDERR instead of STDOUT? Try

output=`/usr/bin/myTool 2>&1`
echo $output

and

`/usr/bin/myTool > output.txt 2>&1`

Hi,
I tried this, but does not seem to work. Any other method ?

The backquotes puzzle me. Are you running this command from a shell prompt or from within another script or executable?

I want to run this command from a Shell Script in the CSHELL on Solaris 8 and want to store the output in a variable.

Ah, you revealed a very important fact, i.e. that you are using the C shell. The syntax for csh is very different than that for bash.

Try the following:

set output = `/usr/bin/myTool`
echo $output

If you want to save output to a file the syntax is

/usr/bin/myTool >& output.txt

Hi,
It does not seem to work.

angshuman_ag, you might want to actually lay out the entire script, including the shebang for us to assist further. This is at least your second thread on this topic, all of which seem to meander back to befuddled.

While we'd like to assist, without more than 'no work' responses, we cannot assist on conjecture. What is your script? What are the args? What is the output to screen...or the return code you're seeing?

I have already laid out the entire script. Its a custom 3rd party tool which return a string always to the console in case of error or success. So, I want to capture that string output in a variable so that I can log that string for debugging purpose. That is the only requirement. If I had the source code of that tool, I could have figured out myself. But, since I have only this much information, hence I thought of posting in this forum.

OK, you now have provided us with another bit of very valuable information. What console is it returning the error to? What system is this on? Is it a GUI or a command line executable?

I don't see a script...although I do see individual command-line calls. Perhaps you're confusing the notion of a script? What shell is it this time? Is it still csh? Previous thread was focused on ksh application of the approach.

If it's on Solaris, have you polled the /var/adm/messages file to see if it's already outputting to a system log?

Hi,
As I have previously said, its a C SHELL on Solaris 8. And, again I will post the "myScript". It looks like this after your suggestion-

set output=`/usr/bin/convert -f inputfile.xcf`
echo "test:\n$output"

Still the above code outputs everything to the console UNIX window when I execute the script like this ./myScript. It echoes its own success/error string in the 1st line on the window followed by "test:" and a BLANK newline. So, the output variable does not have anything yet.

(It does not outputs anyting to system logs). I want to capture the part of string which it echoes before "test:" inside a variable.

does this 'convert' program provide either a --help (or -h) option, a man page or any sort of usage? does it maintain it's own logging, if it's part of a larger application? are we talking Gimp picture files...?

Hi,
These are custom files which have their own format. There is no problem with the conversion or the tool. Its working fine. The only problem is storing its output string.

The help which it provides is very minimal. There are only two options , one which I have provided and other one is -outdir which will put the converted file to the mentioned folder (if provided). There is no man page entry too. Also, it does not maintains any logs. Whatever is there it outputs to the console window. Same output I want to capture.

Thats all the information I have.

curious if you've attempted a bogus option flag, such as -x just to see if it would force a usage message...?

If I give a bogus option flag like you said, it ignores the option and does the conversion successfully. It just requires the input filename. If provided with other flag like -f or -outdir, it will use them else will ignore other flags.

So, the bogus option flag is ignored and no usage mesages are seen.

skip giving it anything...just call it as convert. what's it say?

Like I said, it requires inputfilename. So, if I skip everything and just type convert, then it will show the usage as -

convert [-f] [-outdir] inputXCFFile

Well I'll leave it to you from here. I find you seem to expect a lot of inferences on our part based on what you've shown so far. I don't see anything explicitly worded to support your 'Like I said' comment, but maybe you're assuming a mind meld is underway...it's not.

My only recommendation would be to adopt a better sense of documenting the issue while you take it up with the Vendor. Good luck.

Thats fine. Thanks !
You should read the Rule #2 of this forum -
(2) No negative comments about others or impolite remarks. Be patient.