PDA

View Full Version : Permission denied problem




chidambaram
Sep 15, 2008, 11:42 PM
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....



lee1210
Sep 16, 2008, 12:09 AM
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

chidambaram
Sep 16, 2008, 12:37 AM
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?

gnasher729
Sep 16, 2008, 04:55 AM
My code is

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


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.

robbieduncan
Sep 16, 2008, 07:14 AM
Everything gnasher729 said above is correct and you should really do 3) but if you want a quick and dirty fix try using


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...

chidambaram
Sep 16, 2008, 08:14 AM
thanks for ur reply

system function with open keyword is working fine.

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