This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Temporary files don't work after calling fork.

Tags: None
(comma "," separated)
RyanMcCoskrie
Registered Member
Posts
39
Karma
0
OS
Can somebody please tell me how to work around this problem?

I'm working on a program that needs to be able to execute commands in a temporary file using /bin/sh. The problem is that temporary files made using
KTemporaryFile vanish the moment I call exec.

Since I need to know the name of the file I am using is all of the
recommended subroutines in the C library are out of the picture as well.


RyanMcCoskrie, proud to be a member of KDE forums since 2008-Dec.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
You need to keep the "KTemporaryFIle" object around, because objects created like below will be automatically cleaned up by the compiler when they go out of scope. When the KTemporaryFile instance is destroyed, the file will be deleted also.
Code: Select all
KTemporaryFile myFile;


You need to create the KTemporaryFile as follows:
Code: Select all
KTemporaryFIle * myFile = new KTemporaryFile( <constructor contents> );


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
User avatar
anda_skoa
KDE Developer
Posts
783
Karma
4
OS
Or turn its "auto remove" feature off. See QTemporaryFile (its base class)

Cheers,
_


anda_skoa, proud to be a member of KDE forums since 2008-Oct.


Bookmarks



Who is online

Registered users: Bing [Bot], blue_bullet, Google [Bot], rockscient, Yahoo [Bot]