Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

sourcing the csh script issue

by lpl (Initiate)
on Feb 17, 2017 at 15:35 UTC ( [id://1182212]=perlquestion: print w/replies, xml ) Need Help??

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

hi, i have sourcing script source.csh,in perl i sourced by using the system("csh source.csh")but when sourcing is done it was not setting any required variables, but wen i ran a script in exterm using source source.csh the required vairables are available but in perl source is not supporting how to solve this issue plaz help.....

Replies are listed 'Best First'.
Re: sourcing the csh script issue
by hippo (Bishop) on Feb 17, 2017 at 15:50 UTC

    You have 2 forks going on there - one from system and one from the csh which you've put as part of the command. There's no way that the source.csh code executing in the grandchild process will directly affect anything in the grandparent process.

    The correct approach is to put the env vars in a config file and process that natively in the perl script (or use a module, or source your csh script before starting the perl script, etc.)

Re: sourcing the csh script issue
by thanos1983 (Parson) on Feb 17, 2017 at 16:07 UTC

    Hello lpl,

    Since you did not post any sample code, or parameters I can only assume what you are trying to achieve or what you have already attempted.

    I checked Google and I found this:

    In bash, etc, source is a builtin that means read this file, and interpret it locally (a little like a #include). In this context that makes no sense - you either need to remove source from the command and have a shebang (#!) line at the start of the shell script that tells the system which shell to use to execute that script, or you need to explicitly tell system which shell to use, e.g. system "/bin/sh", "/some/generic/script"; "with no comment about whether it's actually appropriate to use system in this case".

    Source of the answer (How to run “source” command (Linux) from a perl script?).

    I would also recommend to read (How to "source" a shell file in Perl?) it contains some nice answers to similar question and also (Perl system calls in csh Not executing!).

    My question here is also, why to combine both? Is there something that you are trying to do and it can not be done in Perl? Provide us some examples, description of what you are trying to achieve and sample code.

    Hope this helps.

    Seeking for Perl wisdom...on the process of learning...not there...yet!
Re: sourcing the csh script issue
by LanX (Saint) on Feb 17, 2017 at 16:19 UTC
    Your description is vague ...

    ... if you're question is about how to access the environment variables set in a child process, you could use a hack (!) I once posted here:

    Basically dump them to STDOUT and eval them in the parent again.

    See Re^3: How to "source" a shell file in Perl? (Trojan Dump) . The code in the last update is pretty concise

    NB: replace bash with csh

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

      # RVM profile # # /etc/profile.d/rvm.sh # sh extension required for loading. # if [ -n "${BASH_VERSION:-}" -o -n "${ZSH_VERSION:-}" ] && test "`ps -p $$ -o comm=`" != dash && test "`ps -p $$ -o comm=`" != sh then : rvm_stored_umask:${rvm_stored_umask:=$(umask)} # Load user rvmrc configurations, if exist for file in "/etc/rvmrc" "$HOME/.rvmrc" do [[ -s "$file" ]] && source $file done if [[ -n "${rvm_prefix:-}" ]] && [[ -s "${rvm_prefix}/.rvmrc" ]] && [[ ! "$HOME/.rvmrc" -ef "${rvm_prefix}/.rvmrc" ]] then source "${rvm_prefix}/.rvmrc" fi # Load RVM if it is installed, try user then root install. if [[ -s "$rvm_path/scripts/rvm" ]] then source "$rvm_path/scripts/rvm" elif [[ -s "$HOME/.rvm/scripts/rvm" ]] then true ${rvm_path:="$HOME/.rvm"} source "$HOME/.rvm/scripts/rvm" elif [[ -s "/usr/local/rvm/scripts/rvm" ]] then true ${rvm_path:="/usr/local/rvm"} source "/usr/local/rvm/scripts/rvm" fi # Opt-in for custom prompt through by setting: # rvm_ps1=1 # in either /etc/rvmrc or $HOME/.rvmrc if [[ ${rvm_ps1:-0} -eq 1 ]] then # Source RVM ps1 functions for a great prompt. if [[ -s "$rvm_path/contrib/ps1_functions" ]] then source "$rvm_path/contrib/ps1_functions" elif [[ -s "/usr/local/rvm/contrib/ps1_functions" ]] then source "/usr/local/rvm/contrib/ps1_functions" fi if command -v ps1_set >/dev/null 2>&1 then ps1_set fi fi # Add $rvm_bin_path to $PATH if necessary [[ "${rvm_bin_path}" == "${rvm_path}/bin" || ":${PATH}:" =~ ":${rvm_ +bin_path}:" ]] || __rvm_add_to_path prepend "${rvm_bin_path}" fi

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1182212]
Approved by LanX
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2024-04-24 10:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found