Running another program in daemon server

J

janicehwang1325

hi,

I came across a problem which is when i run the server program without
the daemon code, calling another program by `perl second.pl` is just
fine. However, when i put the server to be in daemon, calling to
another program by using `perl <something>.pl` is not working anymore.
What is the cause and how to solve?

Thank you very much.
 
J

Josef Moellers

hi,

I came across a problem which is when i run the server program without
the daemon code, calling another program by `perl second.pl` is just
fine. However, when i put the server to be in daemon, calling to
another program by using `perl <something>.pl` is not working anymore.
What is the cause and how to solve?

Thank you very much.

Making a daemon occasionally involves changing the working directory
(from the Linux manpage of the daemon() function):

"Unless the argument nochdir is non-zero, daemon() changes the current
working directory to the root ("/")."

Check where you are.
 
B

Bart Van der Donck

I came across a problem which is when i run the server program without
the daemon code, calling another program by `perl second.pl` is just
fine. However, when i put the server to be in daemon, calling to
another program by using `perl <something>.pl` is not working anymore.
What is the cause and how to solve?

I would say:

`/path/to/perl /path/to/second.pl`;

or just

`/path/to/second.pl`;

But it's better to avoid backticks unless you need the output of the
external program. See

perldoc -f system
 
X

xhoster

hi,

I came across a problem which is when i run the server program without
the daemon code, calling another program by `perl second.pl` is just
fine. However, when i put the server to be in daemon, calling to
another program by using `perl <something>.pl` is not working anymore.
What is the cause and how to solve?

If $? is nonzero, then the cause, or something resembling it, is in $!.


Xho
 
J

janicehwang1325

Thanks for all the information. It's true that i change the directory
to some other place when i run it as daemon. thank you very much.
 
J

janicehwang1325

The directory is changed to the root directory. However, i try to run
another program using `\path\to\perl \path\to\client.pl` still doesn't
work. is there any other solutions?
 
J

janicehwang1325

Hi,

Just to share with you, my problem is solved by just putting the
program in root directory. It might not be the best solution however,
it did solve my current headache. Anyhow, if there is another way to
solve it, please share with me. Thank you!
 
T

Ted Zlatanov

The directory is changed to the root directory. However, i try to run
another program using `\path\to\perl \path\to\client.pl` still doesn't
work. is there any other solutions?

You may be specifying the path as "\path\to\perl" which won't work.
You need to either use "\\path\\to\\perl" or '\path\to\perl' (single
quotes) or "/path/to/perl".

(ditto for the path to the client)

Generally specify paths for system() with '/' instead of '\' and life
will be easier and more portable.

Ted
 
T

Tad McClellan

Ted Zlatanov said:
Generally specify paths for system() with '/' instead of '\' and life
will be easier and more portable.


But only for the more-than-1-arg form of system().

You cannot use forward slashes with 1-arg system() on
silly "operating systems". (I think.)
 
B

Ben Morrow

Quoth (e-mail address removed):
But only for the more-than-1-arg form of system().

You cannot use forward slashes with 1-arg system() on
silly "operating systems". (I think.)

....unless you change your shell. :)

Ben
 
J

janicehwang1325

I will try based on your advice. thank you very much.


Ben said:
Quoth (e-mail address removed):
But only for the more-than-1-arg form of system().

You cannot use forward slashes with 1-arg system() on
silly "operating systems". (I think.)

...unless you change your shell. :)

Ben

--
'Deserve [death]? I daresay he did. Many live that deserve death. And some die
that deserve life. Can you give it to them? Then do not be too eager to deal
out death in judgement. For even the very wise cannot see all ends.'
(e-mail address removed)
 
T

Ted Zlatanov

But only for the more-than-1-arg form of system().

You cannot use forward slashes with 1-arg system() on
silly "operating systems". (I think.)

Yes, unfortunately that's passed to the command interpreter which will
do violent things to that purty command line. I try very hard to use
the multi-arg system() call to avoid problems like this (and security
problems!). Thanks for catching that.

Ted
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top