Python Forum
sometimes it fails with no messages
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sometimes it fails with no messages
#1
this script i have in file /usr/local/bin/cpp (the parent is in my PATH) which has two errors in it:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import print_function
import os,sys
os.execvp('cp',['cp','-pv']+sys.argv[1:])
raise Exceptiom('execvp failed to execute cp'
would sometimes work (the file would be copied) and sometimes fail (the file would not be copied). every time it would fail there were no messages output. every time it would work it would always output the message from the cp command it was running. before i saw the two errors i tried to run it under strace to have something to check on about the original in case i too quickly changed the file. under strace it did give me a syntax error message and then i saw both errors.

why would it run sometimes? if Python pre-parse everything, first, then shouldn't it always fail with a syntax error for the missing closing parenthesis?

why would it not output an error message when it failed? or could it be doing os.execvp with garbage? any idea why i would get that error message under strace?

this was an old script. i had intended to use Exception back then. i am changing it to OSError.

fixed!

i renamed the command to cppv

now the file /usr/local/bin/cppv looks like:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import print_function
import os,sys
os.execvp('cp',['cp','-pv']+sys.argv[1:])
raise OSError('execvp failed to execute cp')

but i still wonder why it sometimes worked.

and i also still wonder why it would not output a message when it failed.

and why it decided to output the message when i was about to discover why it didn't.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
raise Exceptiom('execvp failed to execute cp'
check spelling!
Reply
#3
that spelling error (probably a typo) was the other of the two errors. it never executed so an unknown name would never have been looked up. it would have been quite odd had it been executed since the syntax error was on that same line.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  logging messages ahead of print messages vindo 6 3,185 Jun-18-2019, 02:45 PM
Last Post: vindo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020