Unix Technical Forum

How do you use 'cdrw' within an application?

This is a discussion on How do you use 'cdrw' within an application? within the Sun Solaris Hardware forums, part of the Solaris Operating System category; --> I'm using a Plextor PX-W1210TSE CD-RW drive on a Solaris 8 system. I'm writing an application in C++ and ...


Go Back   Unix Technical Forum > Unix Operating Systems > Solaris Operating System > Sun Solaris Hardware

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-16-2008, 12:34 PM
M Sudderth
 
Posts: n/a
Default How do you use 'cdrw' within an application?

I'm using a Plextor PX-W1210TSE CD-RW drive on a Solaris 8 system.

I'm writing an application in C++ and need to be able to burn
files/image to a CD from within the application.

'cdrw' may be able to be used, but it's a command-line command. I may
be able to use the "system" operation:
i.e.
system("mkisofs -r <directory> 2>/tmp/cdrw_log | cdrw -i -p 4");

But errors can not be returned to the calling application. This will
only
work in the "happy day" scenario.

Does anyone know how to write/burn files from inside an application?

Surely, there must be a cleaner way.

M Sudderh
msudderth@sfa.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-16-2008, 12:34 PM
Logan Shaw
 
Posts: n/a
Default Re: How do you use 'cdrw' within an application?

M Sudderth wrote:

> I'm using a Plextor PX-W1210TSE CD-RW drive on a Solaris 8 system.
>
> I'm writing an application in C++ and need to be able to burn
> files/image to a CD from within the application.
>
> 'cdrw' may be able to be used, but it's a command-line command. I may
> be able to use the "system" operation:
> i.e.
> system("mkisofs -r <directory> 2>/tmp/cdrw_log | cdrw -i -p 4");
>
> But errors can not be returned to the calling application. This will
> only
> work in the "happy day" scenario.


The proper thing to do would be to create a pipe using pipe().
Then, for mkisofs, do a fork() and connect the child process's
input to /dev/null and stdout to the input end of the pipe
(and close the output end of the pipe in that process). Then
do something similar for cdrw: fork(), open() of /dev/null
and replace stdout with that (using dup2() after closing stdout,
if I recall correctly), close the input end of the pipe, connect
stdin to the output end of the pipe, then exec() cdrw. Finally,
in the parent, close both ends of the pipe (since only the
children need it), and wait() on both the children. The wait()
call will allow you to retrieve the exit code of both child
processes, and this will allow you to determine if the process
worked or not.

Where you send stderr is another question. You could send it
to /dev/null or to a log file or to a second pipe that your
application reads if you want.

Alternately, write a shell script that does the right thing
given the desired parameters, checks the result code of both
processes in the pipe, and returns a single exit code indicating
failure of success. Then just fork() and exec() that shell
script. Or popen() the shell script and make it spit out a
summary of what happened on its stdout, then read the summary
via pipe.

- Logan

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-16-2008, 12:34 PM
Joerg Schilling
 
Posts: n/a
Default Re: How do you use 'cdrw' within an application?

In article <DnQyb.69828$Ek.60053@twister.austin.rr.com>,
Logan Shaw <lshaw-usenet@austin.rr.com> wrote:
>M Sudderth wrote:
>
>> I'm using a Plextor PX-W1210TSE CD-RW drive on a Solaris 8 system.
>>
>> I'm writing an application in C++ and need to be able to burn
>> files/image to a CD from within the application.
>>
>> 'cdrw' may be able to be used, but it's a command-line command. I may
>> be able to use the "system" operation:
>> i.e.
>> system("mkisofs -r <directory> 2>/tmp/cdrw_log | cdrw -i -p 4");
>>
>> But errors can not be returned to the calling application. This will
>> only
>> work in the "happy day" scenario.

>
>The proper thing to do would be to create a pipe using pipe().
>Then, for mkisofs, do a fork() and connect the child process's
>input to /dev/null and stdout to the input end of the pipe
>(and close the output end of the pipe in that process). Then

.....

From listening to some problems with cdrw in the past, it seems that
"cdrw" does not necessarily print an error message when something
did go wrong. I am not sure if the exit code will be != 0 in such
a case....

cdrecord will always print a readable error message and exit != 0
if there was an error. Installing a recent cdrtools package (current
is 2.01a19) grants you also that you use a recent and best bug free
version of mkisofs. Note that even the next version of Solaris 9
will include only mkisofs-1.14 which is now more than 2 years old.

Be sure that you use the mkisofs that comes with the cdrtools package
and not /usr/bin/mkisofs

P.S. meet me at SunNetwork in Berlin

--
EMail:joerg@schily.isdn.cs.tu-berlin.de (home) Jörg Schilling D-13353 Berlin
js@cs.tu-berlin.de (uni) If you don't have iso-8859-1
schilling@fokus.fraunhofer.de (work) chars I am J"org Schilling
URL: http://www.fokus.fraunhofer.de/usr/schilling ftp://ftp.berlios.de/pub/schily
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-16-2008, 12:35 PM
Noel R. Nihill
 
Posts: n/a
Default Re: How do you use 'cdrw' within an application?


"M Sudderth" <msudderth@sfa.com> wrote in message
news:d728b871.0312011303.19746d8c@posting.google.c om...
> I'm using a Plextor PX-W1210TSE CD-RW drive on a Solaris 8 system.
>
> I'm writing an application in C++ and need to be able to burn
> files/image to a CD from within the application.
>
> 'cdrw' may be able to be used, but it's a command-line command. I may
> be able to use the "system" operation:
> i.e.
> system("mkisofs -r <directory> 2>/tmp/cdrw_log | cdrw -i -p 4");
>
> But errors can not be returned to the calling application. This will
> only
> work in the "happy day" scenario.
>
> Does anyone know how to write/burn files from inside an application?
>
> Surely, there must be a cleaner way.


You could use fork(), exec() and waitpid()

> M Sudderh
> msudderth@sfa.com



--
Noel R. Nihill
UNIX® platform development
Motorola NSS
I *could* be arguing in my spare time


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 01-16-2008, 12:35 PM
Peter Bunclark
 
Posts: n/a
Default Re: How do you use 'cdrw' within an application?



Noel R. Nihill wrote:

>"M Sudderth" <msudderth@sfa.com> wrote in message
>news:d728b871.0312011303.19746d8c@posting.google. com...
>
>
>>I'm using a Plextor PX-W1210TSE CD-RW drive on a Solaris 8 system.
>>
>>I'm writing an application in C++ and need to be able to burn
>>files/image to a CD from within the application.
>>
>>'cdrw' may be able to be used, but it's a command-line command. I may
>>be able to use the "system" operation:
>> i.e.
>> system("mkisofs -r <directory> 2>/tmp/cdrw_log | cdrw -i -p 4");
>>
>>But errors can not be returned to the calling application. This will
>>only
>>work in the "happy day" scenario.
>>
>>Does anyone know how to write/burn files from inside an application?
>>
>>Surely, there must be a cleaner way.
>>
>>

>
>You could use fork(), exec() and waitpid()
>
>
>

Use popen(3C) to read back the output.


Pete.

>
>
>
>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 07:16 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com