# Running another program in daemon server

Discussion in 'Perl Misc' started by janicehwang1325@yahoo.com, Jun 22, 2006.

1. ### Guest

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.

, Jun 22, 2006

2. ### Josef MoellersGuest

wrote:
> 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.

--
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett

Josef Moellers, Jun 22, 2006

3. ### Bart Van der DonckGuest

wrote:

> 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

--
Bart

Bart Van der Donck, Jun 22, 2006
4. ### Guest

"" <> wrote:
> 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

--
Usenet Newsgroup Service \$9.95/Month 30GB

, Jun 22, 2006
5. ### Guest

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.

wrote:
> 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.

, Jun 23, 2006
6. ### Guest

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?

Josef Moellers wrote:
> wrote:
> > 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.
>
> --
> Josef Möllers (Pinguinpfleger bei FSC)
> If failure had no penalty success would not be a prize
> -- T. Pratchett

, Jun 23, 2006
7. ### Guest

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!

Josef Moellers wrote:
> wrote:
> > 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.
>
> --
> Josef Möllers (Pinguinpfleger bei FSC)
> If failure had no penalty success would not be a prize
> -- T. Pratchett

, Jun 23, 2006
8. ### Ted ZlatanovGuest

On 22 Jun 2006, wrote:

> 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

Ted Zlatanov, Jun 23, 2006

Ted Zlatanov <> wrote:

> 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.)

--
Perl programming
Fort Worth, Texas

10. ### Ben MorrowGuest

Quoth :
> Ted Zlatanov <> wrote:
>
> > 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.)

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.'

Ben Morrow, Jun 23, 2006
11. ### Guest

Ben Morrow wrote:
> Quoth :
> > Ted Zlatanov <> wrote:
> >
> > > 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.)

>
> ...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.'
>

, Jun 26, 2006
12. ### Ted ZlatanovGuest

On 23 Jun 2006, wrote:

Ted Zlatanov <> wrote:
>
>> 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.)

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

Ted Zlatanov, Jun 27, 2006