Permission denied problem

Discussion in 'Mac Programming' started by chidambaram, Sep 15, 2008.

  1. chidambaram
    Expand Collapse
    macrumors member

    Joined:
    Mar 9, 2008
    #1
    hi,

    I am working in Carbon C application (Mac OS 10.4.7)

    I want to open a pdf file which is placed in the desktop using System command.

    My code is

    system("/Users/laserwords/Desktop/test1.pdf");

    The output is permission denied

    What can i do to rectify this?

    Thanks in advance....
     
  2. lee1210
    Expand Collapse
    macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    That isn't an executable file. You'll need to choose the program and pass the file as an argument, or use some other method to launch the file in the default application. I'm not sure how to do the latter with carbon.

    -Lee
     
  3. chidambaram
    Expand Collapse
    thread starter macrumors member

    Joined:
    Mar 9, 2008
    #3
    thanks for ur reply sir.

    You said "choose the program and select the file"

    Will u please explain this in detail and how can i do that?
     
  4. gnasher729
    Expand Collapse
    macrumors G5

    gnasher729

    Joined:
    Nov 25, 2005
    #4
    1. This call to the "system" function would try to execute the file test1.pdf. Which you obviously can't, and if you could, you wouldn't want to.

    2. Since there is another thread about buffer overflows and security problems, I'd just say that the system function can lead to some rather nasty security holes.

    3. Have a look at the LaunchServices APIs. Especially LSOpenCFURLRef and LSOpenFSRef.
     
  5. robbieduncan
    Expand Collapse
    Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #5
    Everything gnasher729 said above is correct and you should really do 3) but if you want a quick and dirty fix try using

    Code:
    system("open /Users/laserwords/Desktop/test1.pdf");
    
    This should call the command line open utility that will use Launch Services to open the file in the correct application...
     
  6. chidambaram
    Expand Collapse
    thread starter macrumors member

    Joined:
    Mar 9, 2008
    #6
    thanks for ur reply

    system function with open keyword is working fine.

    please give some sample code for LSOpenFSRef() and LSOpenCFURLRef()
     

Share This Page