For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > May 2004 > RE: working directory with exec command









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author RE: working directory with exec command
Bob Showalter

2004-05-18, 10:32 am

Peterson, Darren - Contractor.Westar wrote:
> I'm trying to use fork and exec to kick-start other processes on a
> Linux box. As with Win32::Process::Create, I'd like to somehow
> specify or point towards a working directory for the new process
> since some data files are expected via relative path. I actually
> tried passing a compound command such as "cd
> /home/otbsaf/OTBSAF/src/OTBSAF;./otbsaf" to exec to hope a directory
> switch would happen as I intended. The new process displays its
> current directory and the directory shown was that from which the
> perl script was running, not the hoped for otbsaf.


Just use Perl's chdir() after you fork:

defined(my $pid = fork) or die $!;
unless ($pid) {
chdir('/home/otbsaf/OTBSAF/src/OTBSAF') or die $!;
exec './otbsaf' or die $!;
}
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com