ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
freeMB's value and "hello" are echoed to /tmp/somefile
but values ${cpu[index]} aren't echoed to /tmp/somefile. However, they are echoed to screen.
Is it true that the value of cpu such as: 30.0% causes such problem because of the "%" ?
Is there any way to echo those values to a file?
Actually, I invoke that script above from a java file. That causes problem with the echoing of array cpu.
But if i was to run the script directly, it's fine.
through java, the script is called and it is supposed to echo all values that i wanted to a file, but it only does some and ignore those values of array.
I know my Proccess call work, because it was able to read the data out of the file. The problem here is, the getResource doesn't echo values of my array to the destined file; it echos everything else. When I open the output file, I only see regular string like "hello", but not the values of array.
If I was to run getResource directly w/o going through java, then it works fine.
Distribution: LFS, I felt the itch and scratched it
Posts: 227
Rep:
Are you taking into account that your script writes it out to /tmp/$i and your java program is reading from the current directory for the file that was output? It seems to work for me if I make the script write to the current directory.
the script will send its output to a file
my java program will read that output
some how the output is missing the values of array. I suspect that, the command "top -n 1" within the script return output to a different console, that's why my array didn't get the values back from "top -n 1". And that's why no values of the array were sent to output fie
Distribution: LFS, I felt the itch and scratched it
Posts: 227
Rep:
Try "top -b -n 1" to make top run in batch mode.
Quote:
-b : Batch mode operation
Starts top in 'Batch mode', which could be useful for sending out-
put from top to other programs or to a file. In this mode, top
will not accept input and runs until the iterations limit you've
set with the '-n' command-line option or until killed.
It seems to run correctly with that. It should also produce cleaner output since it doesn't output any ASCII color codes.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.