Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Can't open Perl output from within Nautilus

by hweefarn (Acolyte)
on Dec 25, 2003 at 09:17 UTC ( [id://316967] : perlquestion . print w/replies, xml ) Need Help??

hweefarn has asked for the wisdom of the Perl Monks concerning the following question:

hi :)

in my program, i open a file and write something into it. but when i go to the directory and open the file that i just created, got error message said "Nautilus has no installed viewer capable of displaying "/home/a/mail/yahoo/2512200317146"."
anyone knows why?

this is my scritps:
if ($from eq $field18) { #build filename $tm=localtime; ($year,$month,$day)=($tm->year+1900, ($tm->mon)+1, $tm->mday); ($hour,$min,$sec)=($tm->hour, $tm->min, $tm->sec); #$filename=$day.$month.$year.$hour.$min.$sec."\.txt"; $filename=$day.$month.$year.$hour.$min.$sec; #go in to the right directory $base="/home/".$userID."/mail/".$field21; chdir("$base"); #build the full path name $full=$base."\/".$filename; #open the file first open(OUTFILE2, ">$full") or die "Can?t open file: $!"; #write to the file print OUTFILE2 "From: ", $from, "\n"; print OUTFILE2 "To: ", $to, "\n"; print OUTFILE2 "Subject: ", $subject, "\n"; print OUTFILE2 "Message body: ", "\n", $body, "\n"; close OUTFILE2; #change file permission chmod (0666, "$full"); }


thanks


hweefarn

20031225 Edit by Corion: Added code tags

Title edit by tye

Replies are listed 'Best First'.
Re: file problem
by TomDLux (Vicar) on Dec 25, 2003 at 17:50 UTC

    If you select the file in Nautilus and right click to display a menuu, then select "Open With >> A Viewer...", a window will pop up saying, "No viewers are available for '25122003123434'". The window has two buttons, "Cancel" and "Associate Application". Select "Associate Application" and a new window appears.

    You'll see Nautilus identifies the file as an "email message/mailbox", MIME type "message/rfc822"

    The second last line in the box reads "Program (            ) (Browse)". Click on the browse button and locate the program you would like to use as the viewer for mail messages ... emacs? vi? Evolution? Pine? You decide.

    --
    TTTATCGGTCGTTATATAGATGTTTGCA

Re: file problem
by allolex (Curate) on Dec 25, 2003 at 16:11 UTC

    This isn't really a problem with Perl, but try using the "less" command with the full path of the file you want to open. You'll have to open the console/terminal application for that (or try hitting CTRL-ALT-F1 on your keyboard and logging in from there).

    less /home/hweefarn/mail/myfile

    Nautilus is the Gnome Desktop's file manager. It probably either has no file type detection, or has it turned off. That means it is, like Microsoft Windows, probably looking for a filename extension (e.g. '.txt') to identify the type of file you are opening. (Konqueror in the KDE desktop does a pretty good job of this, but I don't have Gnome handy where I am right now, so I can't just tell you the settings you'll need).

    --
    Allolex

    PS: Instead of "\/", try using '/'.

      Actually, all sane software on a Unixoid system should be using .mailcap and .mime.types (see man 5 mailcap and man 5 mime.types). Last I checked, this was the case for the filemanagers (and other tools) of both desktops.

      Makeshifts last the longest.

Re: file problem
by b10m (Vicar) on Dec 25, 2003 at 09:35 UTC

    Have you inspected the contents of the output? As I see it, this is not the problem of your script, but rather of "Nautilus". I haven't used Nautilus ever, so couldn't help you to set up a "capable viewer", but Google tells us that you need gedit. If that fails, try:

    $ file /home/a/mail/yahoo/2512200317146
    to see what kind of file you're dealing with.

    HTH

    --
    b10m

      The code shows that the output is a mail file. :) I don't know if it was there when you posted.

      print OUTFILE2 "From: ", $from, "\n"; print OUTFILE2 "To: ", $to, "\n"; print OUTFILE2 "Subject: ", $subject, "\n"; print OUTFILE2 "Message body: ", "\n", $body, "\n";

      --
      Allolex

Re: file problem
by bart (Canon) on Dec 25, 2003 at 22:45 UTC
    You're creating a file of which the name consists of nothing but a bunch of digits. I think it'd be saner of you to use a file extension. Choose one which your system can then associate with the kind of file it really is. You could start with appending ".txt" to your file name, for example, to get a feel for it.

      Unix is not based on file extenstions. You're thinking of DOS.

      --
      TTTATCGGTCGTTATATAGATGTTTGCA