Hello,
I start fileevents as soon as my tk code is invoked. My widget gets updated based on the fileevents. Most of the files do not exist in the beginning and so I get the following messages on the prompt where I invoked the perl/tk program. tail 'filename' for reading:no such file or directory.
The widget update works fine. But is there anyway that I can prevent these messages from showing up. Also when information starts streaming into these files, the message below shows up, tail: 'filename' has appeared; following end of new file
I would like to avoid these kinds of messages while executing my code.
How can I do this.
11 6635
As a small example,
I open my file using
#!/usr/bin/perl -w open(FILE, "tail -F -n 10 $file |") or die "Error $!\n"; 'tail cannot open <filename> no such file or directory'
is written out to my shell.
How can I hide this.
open(FILE, "tail -F -n 10 $file |") or die;
That doesnt work either. I still get the message on my shell.
The message does not come from the Error $! but gets dumped out when perl tries to execute tail to open the file.
As a small example,
I open my file using -
#!/usr/bin/perl -w
- open(FILE, "tail -F -n 10 $file |") or die "Error $!\n";
-
'tail cannot open <filename> no such file or directory'
is written out to my shell.
How can I hide this.
In the above example, "$file" is never assigned a value. So essentially you're calling "tail -F -n 10 |" which while legal is not useful as it returns the above error. Try assigning a value to '$file', and alternatively, try using the cpan module for tailing files. http://search.cpan.org/search?query=File::Tail
In the above example, "$file" is never assigned a value. So essentially you're calling "tail -F -n 10 |" which while legal is not useful as it returns the above error. Try assigning a value to '$file', and alternatively, try using the cpan module for tailing files. http://search.cpan.org/search?query=File::Tail
Hello Miller,
I just put in $file as an example. In my code I assign it a value. Anyway if the file does not exist, the tail warning comes up. As an example
Assume my file ./test.txt does not exist
#!/usr/bin/perl
$file = "./test.txt"
open(FILE, "tail -F -n 10 $file") or die;
gives out the tail warning saying no file or directory.
Once I cat some value into the file ./text.txt the tail handler gets updated and works fine.
It is the initial tail messages that I want to avoid popping up on my screen.
Hi Natti,
Then quite simply, add logic that will ensure that the file exists first before calling tail. Read about all the special file tests here: http://perldoc.perl.org/functions/-X.html -
#!/usr/bin/perl
-
use strict;
-
my $file = "./test.txt"
- if (-e $file) {
-
open(FILE, "tail -F -n 10 $file") or die;
-
}
-
Hi Natti,
Then quite simply, add logic that will ensure that the file exists first before calling tail. Read about all the special file tests here: http://perldoc.perl.org/functions/-X.html -
#!/usr/bin/perl
-
use strict;
-
my $file = "./test.txt"
- if (-e $file) {
-
open(FILE, "tail -F -n 10 $file") or die;
-
}
-
Hello Miller,
Thanks for the info on this post. I tried that already. However, I go into the subroutine and start the tail process for a list of files at the beginning of execution. That prevents me from using the -e option.
I managed to overcome this problem by making sure that the file exists before the subroutine is called. i.e. I will cat a null value into the file if it does not exist.
Natti
@Natti
Try to redirect STDERR! (this is where I assume your messages are printed to)
Depending on your Shell, this should look like: - open(FILE, "tail -F -n 10 $file 2>& /dev/null") or die;
Greetz, Doc
@Natti
Try to redirect STDERR! (this is where I assume your messages are printed to)
Depending on your Shell, this should look like: - open(FILE, "tail -F -n 10 $file 2>& /dev/null") or die;
Greetz, Doc
docsnyder,
I am open a pipe to the tail and then using the fileevent. The redirection to /dev/null does not work and I get the following error message. sh: /dev/null: ambiguous redirect
@Natti
You could, as a workaround, redirect STDERR to STDOUT. - open(FILE, "tail -F -n 10 $file 2>&1 |") or die "$!";
This would force error messages to be channeled through the pipe as well.
When reading from the pipe, the error messages could simply be skipped.
Not nice, of course, but serves your needs.
Greetz, Doc
Redirect stderr to /dev/null instead of another descriptor, like this:
2>/dev/null
I use this when I want stdin/stdout but want to ignore errors.
#!/usr/bin/perl
`rm file.notexist 2>/dev/null`;
`cat part1.txt >> whole.txt 2>/dev/null`;
Hope that helps...
Sign in to post your reply or Sign up for a free account.
Similar topics
by: francescomoi |
last post by:
Hi.
I'm trying to build 'MySQL-python-1.2.0' on my Linux FC2:
----------------------------------
# export PATH=$PATH:/usr/local/mysql/bin/
# export mysqlclient=mysqlclient_r
# python setup.py...
|
by: Hugz |
last post by:
Hello,
And Thank you for taking time to help me.Myself Hugz.I am new to
perl and want to write my own Scripts.But i can't understand how perl
"rename" function and "file locking" works.
...
|
by: James A. Donald |
last post by:
I am contemplating getting into Python, which is used by engineers I
admire - google and Bram Cohen, but was horrified to read
"no variable or argument declarations are necessary."
Surely that...
|
by: news.bellatlantic.net |
last post by:
I created a for with file inputs (<input type=file.../>) I named them file1,
file2, file3 etc. How do I access them in the code behind without actually
calling each one by name (there are 21 of...
|
by: Steve Chatham |
last post by:
I am stuck on this. It ought to be a simple reason as to why this is
problematic, in that it works on smaller groups of data (say under 40
records), but doesn't on larger groups of records (40+)....
|
by: RSH |
last post by:
Hi,
I have an ASP .Net web page that creates a temp directory on the server then
it is using the File.Copy command to move a file to a temp download
directory, Then I am doing a...
|
by: comp.lang.tcl |
last post by:
set php {<? print_r("Hello World"); ?>}
puts $php; # PRINTS OUT <? print_r("Hello World"); ?>
puts
When I try this within TCL I get the following error:
|
by: naveeddil |
last post by:
Hello,
I use this command for including my ASP files into another
it is working perfectly on my XP 2002 SP2, IIS server and also i upload to brinkster.com and working perfectly there but here is...
|
by: dissectcode2 |
last post by:
Hi - I know almost nothing about Perl but do program in other languages. I am looking at Perl that I have to modify slightly by printing a "file not found" message if a file is missing from the...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |