in reply to Re: Calling Shell funtion in Perl script
in thread Calling Shell funtion in Perl script

This pscnt function is to determine if any program name (and parameter) passed in is actually a running process. If so, returns count of running instances. I tried this code, but I get count as 2. my $running = `. ~/.profil > /dev/null; pscnt $app_name $parameter`; I am not sure if the code is correct. So, please help me to sort out this issue.
  • Comment on Re^2: Calling Shell funtion in Perl script

Replies are listed 'Best First'.
Re^3: Calling Shell funtion in Perl script
by ambrus (Abbot) on May 24, 2005 at 20:37 UTC

    This should work.

    In . ~/.profil > /dev/null, is the missing e a typo that appears in your real code too?

    Also the `` operator is calling /bin/sh, so if you are using a different shell (such as zsh), this may not work. Even if you are using bash, it may be invoked as sh and thus it is running in POSIX compatibility mode. You could try `set +o posix; . ~/.profile > /dev/null; whatever`

    If the code still doesn't work, try this for debugging so that you see what commands the shell runs: my $result = `set -v; set +o posix; . ~/.profile > /dev/null; whatever`

    Also, you might want to move the shell function from your profile to a separate shell script, so that you don't have to run the whole profile from our perl script. (You can still source the separate file from your profile.)