fopen can't open .exe?

This is a discussion on fopen can't open .exe? within the C Programming forums, part of the General Programming Boards category; Is there a reason why I can't open a .exe file with fopen? I've got a function that's supposed to ...

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    27

    fopen can't open .exe?

    Is there a reason why I can't open a .exe file with fopen? I've got a function that's supposed to copy some files. It's copying all kinds of files fine (e.g. .doc, .htm, .asm, .inc). But I get an error when it tries to open a .exe file.

    I'm working on WinXP, and my program runs from the command line. If fopen is not supposed to be able to open .exe file, what can I use? Thank you.

  2. #2
    Registered User
    Join Date
    May 2006
    Posts
    903
    It works on my computer. I'd think you need to specify read-only access.

  3. #3
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,739
    Alternatives to what you are doing are explained in the FAQ: see, How Do I ... Run another program from within a program.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,671
    > But I get an error when it tries to open a .exe file
    Here's a tip - post the actual error message(s)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,169
    Are you maybe trying to fopen() a running .exe program? If it's currently running you won't be able to fopen() it in write mode.
    If you understand what you're doing, you're not learning anything.

  6. #6
    Just kidding.... fnoyan's Avatar
    Join Date
    Jun 2003
    Location
    Still in the egg
    Posts
    269
    Well, as I know open() is used to open files in binary and ascii mode. So, give a try to it!

  7. #7
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,169
    Quote Originally Posted by fnoyan
    Well, as I know open() is used to open files in binary and ascii mode. So, give a try to it!
    open() is just a system call that fopen() uses internally. It would undoubtedly fail just as fopen() does. Without the actual error message we'll never know, but open()'s not going to succeed if fopen() is failing.

    Did you realize that (without the 'f'), the letters in your name can be used to make the word "annoy"? That's interesting.
    If you understand what you're doing, you're not learning anything.

  8. #8
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    >> Did you realize that (without the 'f'), the letters in your name can be used to make the word "annoy"? That's interesting.

    Iceburn!
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  9. #9
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    It's copying all kinds of files fine (e.g. .doc, .htm, .asm, .inc). But I get an error when it tries to open a .exe file
    The error is when you run the copied exe, right? Open the file in binary mode, and don't use a char to store EOF.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  10. #10
    Registered User
    Join Date
    Jun 2006
    Posts
    27
    Thanks for your help. Figured it out finally.

  11. #11
    Registered User
    Join Date
    Apr 2011
    Posts
    1
    I'm having a similar issue. can you share with me how you did it?


    Thanks.

  12. #12
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    This thread is five years old. Why didn't you just make a new one?


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fopen and open
    By ygfperson in forum Linux Programming
    Replies: 2
    Last Post: 06-29-2005, 08:34 PM
  2. open or fopen?
    By Tibo in forum C Programming
    Replies: 2
    Last Post: 03-27-2003, 09:14 AM
  3. Command to open the 'Open Dialog Box' found in most programs.
    By OmegaFirebolt in forum Windows Programming
    Replies: 5
    Last Post: 03-16-2003, 07:58 PM
  4. file doesn't open
    By jmoney in forum C Programming
    Replies: 6
    Last Post: 02-24-2003, 01:39 PM
  5. Problems with open and save boxes
    By pinkcheese in forum Windows Programming
    Replies: 3
    Last Post: 05-21-2002, 06:03 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21