G'day astronogun,
While there's quite a few issues with the code you posted, I see nothing that would prevent appending to a text file:
$ ls -l input.txt
ls: input.txt: No such file or directory
$ perl -e '$input = q{input.txt}; @output = system ("ls -l >> input.tx
+t");'
$ ls -l input.txt
-rw-r--r-- 1 ken staff 16393 12 Mar 15:34 input.txt
Here's some of the issues I found with your code:
-
Unless you have a very good reason not to, always put "use strict;" and "use warnings;" at the start of your code. See strict and warnings.
-
Use meaningful names. You've called your output file input.txt and assigned that to a variable called $input. You also don't use the variable $input: I'm wondering if that was just an oversight or is input.txt actually an input file!
-
system does not return an array but you're assigning its return value to @output. Again, I'm left wondering if this was just a poor naming choice coupled with a failure to check the documentation or are you actually expecting output from your java ... command to be placed in @output.
-
You really need check return values. system gives a good description of how to go about this; it also mentions use of the autodie pragma.
I'd suggest something like the following code as a starting point from which you can inspect return values and investigate your problem further.
$ perl -e '
use strict;
use warnings;
use autodie qw{:all};
my $output_file = q{output.txt};
my $return_value = system "ls -l >> $output_file";
'
You'll note both here, and earlier, that I've used a simple ls -l command to test the code. I'd suggest you do the same, to check whatever file-appending problem you're experiencing, before trying with "java -jar cmdline-jmxclient-0.10.3.jar - localhost:1100 com.ogs.red5.client.manager:name=Manager getConnectedAgents" which may have its own issues that could be masking your reported problem.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.