Re: How do you use 'cdrw' within an application?
From: Logan Shaw (lshaw-usenet_at_austin.rr.com)
Date: 12/02/03
- Previous message: M Sudderth: "How do you use 'cdrw' within an application?"
- In reply to: M Sudderth: "How do you use 'cdrw' within an application?"
- Next in thread: Joerg Schilling: "Re: How do you use 'cdrw' within an application?"
- Reply: Joerg Schilling: "Re: How do you use 'cdrw' within an application?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 01 Dec 2003 23:44:35 GMT
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
- Previous message: M Sudderth: "How do you use 'cdrw' within an application?"
- In reply to: M Sudderth: "How do you use 'cdrw' within an application?"
- Next in thread: Joerg Schilling: "Re: How do you use 'cdrw' within an application?"
- Reply: Joerg Schilling: "Re: How do you use 'cdrw' within an application?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|