473,387 Members | 1,590 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Hiding tail "no such file or directory" message in Perl/Tk

15
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.
Feb 16 '07 #1
11 6635
Natti
15
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.
Feb 17 '07 #2
KevinADC
4,059 Expert 2GB
open(FILE, "tail -F -n 10 $file |") or die;
Feb 17 '07 #3
Natti
15
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.
Feb 17 '07 #4
miller
1,089 Expert 1GB
As a small example,

I open my file using
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w
  2. open(FILE, "tail -F -n 10 $file |") or die "Error $!\n";
  3.  
'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
Feb 17 '07 #5
Natti
15
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.
Feb 17 '07 #6
miller
1,089 Expert 1GB
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

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. use strict;
  3. my $file = "./test.txt"
  4. if (-e $file) {
  5.     open(FILE, "tail -F -n 10 $file") or die;
  6. }
  7.  
Feb 17 '07 #7
Natti
15
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

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. use strict;
  3. my $file = "./test.txt"
  4. if (-e $file) {
  5.     open(FILE, "tail -F -n 10 $file") or die;
  6. }
  7.  

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
Feb 18 '07 #8
@Natti

Try to redirect STDERR! (this is where I assume your messages are printed to)

Depending on your Shell, this should look like:
Expand|Select|Wrap|Line Numbers
  1. open(FILE, "tail -F -n 10 $file 2>& /dev/null") or die;
Greetz, Doc
Feb 19 '07 #9
Natti
15
@Natti

Try to redirect STDERR! (this is where I assume your messages are printed to)

Depending on your Shell, this should look like:
Expand|Select|Wrap|Line Numbers
  1. 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
Feb 22 '07 #10
@Natti

You could, as a workaround, redirect STDERR to STDOUT.
Expand|Select|Wrap|Line Numbers
  1. 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
Feb 22 '07 #11
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...
May 1 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

2
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...
3
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. ...
134
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...
2
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...
0
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+)....
7
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...
21
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:
2
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...
2
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...
0
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$) { } ...
0
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...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
marktang
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,...
0
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...
0
Oralloy
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.