Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

chidambaram

macrumors member
Original poster
Mar 9, 2008
67
0
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

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
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

macrumors member
Original poster
Mar 9, 2008
67
0
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

Suspended
Nov 25, 2005
17,980
5,566
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

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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...
 

chidambaram

macrumors member
Original poster
Mar 9, 2008
67
0
thanks for ur reply

system function with open keyword is working fine.

please give some sample code for LSOpenFSRef() and LSOpenCFURLRef()
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.