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

hello folks, i want to execute run_dynamic.csh file from my perl script. also my cshell file consist of environment variables command like setenv. i tried system("csh","file pointer"); but not working. please throw some light on it. thanks, argha

Replies are listed 'Best First'.
Re: execute csh file from perl script
by Corion (Patriarch) on Jul 31, 2015 at 11:49 UTC

    See Get default login environment if you want the environment variables set up by the child script to be available to your Perl script.

    Update

    As discussed in the CB, RE (tilly) 3: Get default login environment has most of what you need. You might need to adapt the shell invocation to run your script instead of the default login setup:

    sub get_login_env { local %ENV; my $csh = shift; my $env = `$csh ; env`; if (wantarray) { my @pieces = ($env =~ m/^(.*?)=((?:[^\n\\]|\\.|\\\n)*)/gm); s/\\(.)/$1/g foreach @pieces; return @pieces; } else { return $env; } }
Re: execute csh file from perl script
by afoken (Chancellor) on Jul 31, 2015 at 11:51 UTC
    hello folks, i want to execute run_dynamic.csh file from my perl script. also my cshell file consist of environment variables command like setenv. i tried system("csh","file pointer"); but not working. please throw some light on it. thanks, argha

    From your very verbose and informative posting, it is absolutely clear that the error is in line 42.

    If you want serious answers, show some efforts in your postings:

    • relevant code
    • error messages
    • actual output
    • expected output
    • all unmodified except for passwords and other sensitive data
    • all copied from actual files / output, not typed manually
    • each wrapped in <code></code>

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re: execute csh file from perl script
by salva (Canon) on Jul 31, 2015 at 12:12 UTC
    system("csh", "-c", $cmd);
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: execute csh file from perl script
by hippo (Archbishop) on Aug 01, 2015 at 10:44 UTC

    You should definitely read Csh programming considered harmful and then decide whether to use a Bourne-like shell instead or (better) to convert the whole thing to Perl thus avoiding the fork, the shell invocation, the parent problem, FD changes, output/error grabbing, etc.