sagibeli has asked for the wisdom of the Perl Monks concerning the following question:

Even when i run this system command: system("source pwd") i get this error. of any other file or script instead of ./profile Any suggestions??? Thanks, Sagi
  • Comment on the command - system ( "source ./profile") not working

Replies are listed 'Best First'.
Re: the command - system ( "source ./profile") not working
by moritz (Cardinal) on Jan 10, 2008 at 09:38 UTC
    source is a shell builtin, not a command.

    .profile is usually a shell script which can be run with sh .profile, but I don't think it will do you any good (because .profile usually sets environment variables which are lost after system)

Re: the command - system ( "source ./profile") not working
by f00li5h (Chaplain) on Jan 10, 2008 at 09:38 UTC

    source is a bourne builtin, it's not a real executable...

    what are you actually trying to do here? even if it did source the contents of your .profile, the aliases/variables would belong to the sub-shell (the one that was spawned by system, and then terminated after reading execiuting the one operation you gave it)

    Are you looking for some kind of config file for your script perhaps?

    Updated grammar, and links

    @_=qw; ask f00li5h to appear and remain for a moment of pretend better than a lifetime;;s;;@_[map hex,split'',B204316D8C2A4516DE];;y/05/os/&print;

Re: the command - system ( "source ./profile") not working
by Corion (Patriarch) on Jan 10, 2008 at 09:43 UTC

    All the changes made by a shell script will be undone once the process started by system() finishes. Most likely you want to the technique outlined in Get default login environment if you need to set up a runtime environment of a shell script from within Perl.

Re: the command - system ( "source ./profile") not working
by cdarke (Prior) on Jan 10, 2008 at 11:24 UTC
    i get this error

    Which error is that then? 'source' is a built-in to csh or bash to read and execute a file without creating a child process, 'pwd' is a built-in shell command, so I'm not surprised you get an error. What is it you are trying to do? If you want to get the current working directory use Cwd.

    Using another program, like a shell, to do simple stuff like that is like employing someone else to tie your shoe laces - expensive and slow.
      The problem is that you are trying to execute "source" which is not a real program. It is a bash builtin command. Try the following: my $XYZZY=`bash -c "source SOME-FILE; DO WHATEVER"`;
Re: the command - system ( "source ./profile") not working
by rgiskard (Hermit) on Jan 10, 2008 at 12:56 UTC
    Without seeing your error, why dont you do some testing with absolute paths. like:  system("source /home/perlmonkey/.profile").

    For debugging purposes, I would suggest using the backtick approach to see any stdout: print `source /home/perlmonkey/.profile`

    Do note, your sourced profile will exist in the subshell you called it in. So to test it further you will have to do something like print `source .profile;echo $PATH` which assumes that there exists a path var in the shell.

    Hopefully your in some type of linux enviroment, otherwise the commands you were calling would be somewhat faulty.

    UPDATE:Take a look at the answer in the following node 616002 as it addresses the problem of sourcing a license which could be quite similar to your problem.