Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Hidden Characters?

by tame1 (Pilgrim)
on Nov 14, 2000 at 00:39 UTC ( #41416=perlquestion: print w/replies, xml ) Need Help??

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

Recently, (and ONLY recently) I have begun experiencing a problem which I should not be having.

We are all familiar with what happens when you transfer a file with the wrong method, etc.? the #! line gets a hidden character and you can't run the program from the command line.

Well, lately when I write a program with my emacs (this is on a linux system), and I run it from the command line, I get the old "text file busy" response. I have to cp the file to somewhere else, then cp it back. Suddenly it will work.

Why is emacs suddenly inserting some kind of hidden character? This hasn't happened before in the years I have used emacs! Please help!
CC reply to please.

Replies are listed 'Best First'.
RE: Hidden Characters?
by lemming (Priest) on Nov 14, 2000 at 01:42 UTC
    Warning! Probably not the solution. I've had this problem before and I don't think it's a DOS/UNIX test problem. (Some years ago at a different company.)
    However, see if the program operate differently if you type
    $ perl
    With 5.6 on redhat 6.2 a Dos newline will run example #1, but not #2. (bash command not found)
    Back to the problem
    It might be a system problem. Check your inode space. Do a df -i. I don't think that's the case, but some other system resource is hanging you up.
    The previous posts give good clues as well. Is this a program that performs writes? I know I ran into this problem before and it was most likely with a program that opened multiple files and wrote out log files. This problem is really bugging me that I don't remember the solution.
    Hopefully this will give you an area in which to look.

    UPDATE: Another idea. Are you using Samba or maybe NFS? For some reason that's tickling the back of my brain.
Re: Hidden Characters?
by AgentM (Curate) on Nov 14, 2000 at 00:59 UTC
    Are you referring to the FTP "problem" where Win or Mac to Linux files throw in an extra char for newlines? In that case, ALL newlines are affected, not just the first line. I'm not sure whether Perl likes funky chars like ^M in it's parsing engine, so a sort of converter would be in order. All it needs to do is convert the DOS newline to the '\n' (that's the C character \n and not the Perl \n for your info, but under Linux the C code is \n anyway...) I'm sure there is already one readily available somewhere on this site....hmmm...

    The second problem (seemingly unrelated) deals with a text file busy response. That's not a perl error response (at least not in <5.6 since I just looked it up in an old book) and probably has something to do with a mandatory lock failure on open(). I can't imagine that perl tries to lock the file (does it, though?), so you are probably using a linux kernel with mandatory locking compiled that right? Anyway, I don't think emacs is locking the file (it does not, by default, unless...well, not by default). What made you cp it somewhere else and back. If this were mandatory locking, cp would fail on the open read just as perl would. No- something is fishy in your story. (p.s. emacs will not IN ANY FASHION insert a hidden character as you propose unless you save it in some strange manner (DOS mode?) and these two problems that you are having are unrelated!)

    AgentM Systems nor Nasca Enterprises nor Bone::Easy nor Macperl is responsible for the comments made by AgentM. Remember, you can build any logical system with NOR.
Re: Hidden Characters?
by tame1 (Pilgrim) on Nov 14, 2000 at 01:55 UTC
    In re: to everyone who responded:

    ems::jrobiso2-->perl works fine
    ems::jrobiso2-->./ gives the "error opening text file" message

    I've closed emacs and tried running it - no avail.
    Only cp the file seems to clear up the message

    What does this little button do . .<Click>; "USER HAS SIGNED OFF FOR THE DAY"
      Two questions:
      1. Does the output of 'which perl' (on the command-line) differ from the first line of your Perl script (in other words, are you calling two different versions of the same Perl executable)? Perhaps it's the Perl binary itself that's giving you this error message.
      2. Try viewing your script with 'vi' or 'view', which typically gives you a better view of any embedded control characters (such as an evil trailing DOS newline). A standard pager (like less or more) typically ignores trailing ^M's. Emacs may also.
      3. Do you have 'lsof' on your system? Is there any way you can identify any other applications that might have this script open? Perhaps Emacs is somehow continuing to hold a lock?
      The open syscall can fail with this message (ETXTBSY), but usually only if the requested file is being executed (which may not be the case or make sense in this instance, since Perl scripts aren't so much executed as they are read by the Perl interpreter) when an open request comes in with O_WRONLY or O_RDWR flags. This doesn't really make a lot of sense.

      What operating system are you using? I'd like to dig further on the cases where you'd get this message. I'd also kinda like to see the first line of your script, the location of your Perl binary, and the permissions of your script.

        Let's see....ok. The "regular" perl binary is /usr/bin/perl (which is itself a link to /usr/bin/perl-5.00503

        My shebang is #!/usr/local/bin/perl -w which is a symlink to /usr/bin/perl

        So yes, there are two levels of syms involved.
        However, I think one of the earlier guys had it - my emacs is saving in DOS mode. Why, I have no idea. How to stop it, I also don't know. Does anyone?

        What does this little button do . .<Click>; "USER HAS SIGNED OFF FOR THE DAY"
RE: Hidden Characters?
by mitd (Curate) on Nov 14, 2000 at 10:47 UTC
    Horse dickies! If one would would like to confirm or deny hidden chars from within emacs just:
    M-x hexl-mode[RET] or M-x hexlify-buffer[RET]

    A 'dickey or dicky' was a fake turtle neck usually worn under a V neck sweater and made popular by Herman's Hermits in the 60's. Not that other thing you thought it... oh lets just not go there

    Whenever I use vi my pinky gets tired. Why is that?

    mitd-Made in the Dark
    'My favourite colour appears to be grey.'

      Yeah - I know. That's why this is so wierd. There appear to be NO hidden characters!!! What does this little button do . .<Click>; "USER HAS SIGNED OFF FOR THE DAY"
      How do hidden characters show up in hexl-mode?
Re: Hidden Characters?
by Fastolfe (Vicar) on Nov 14, 2000 at 00:42 UTC
    Is emacs still open, or do you exit it before you try to run your script? It sounds almost like a program is putting a lock on the file, preventing it from being read by another application. It's not inserting any characters.

    Update: Typically you get this error when you attempt to execute or write to a file that is currently being written to. So it may have less to do with locking and more to do with slow writes? Note that you can get this error against the Perl binary itself, not just a script. Don't be misled by the word "text".

    The solution is just to wait until Emacs is finished saving the file. If you're sure this is the case, and you continue to consistently get this error message even after exiting Emacs, maybe do an 'lsof' on the file and see if you can identify any other applications that have it open.

    Update: Note that Re: Hidden Characters? makes these theories unlikely. Very weird problem.

Re: Hidden Characters?
by b (Beadle) on Nov 14, 2000 at 00:44 UTC
    Your problem is not so clear. Anyway, some Emacs versions save files in 'DOS mode' which has \r\n as end-of-line markers

    Do you have "DOS" at the bottom of the screen?

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://41416]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2021-07-31 00:28 GMT
Find Nodes?
    Voting Booth?

    No recent polls found