1

So, I'm trying to source a file via Python. The code goes something like this:

import os
source = 'source /home/software/cadence/release2013/setup/xyz.setup p'
os.system(source)

This gives the following:

/home/software/cadence/release2013/setup/xyz.setup: line 23: syntax error near unexpected token `$HT'
/home/software/cadence/release2013/setup/xyz.setup: line 23: `switch ($HT)'

Now, I assure you. There is nothing wrong with xyz.setup. It's been sourced countless times and by many people. Also, when I directly source it via terminal

source /home/software/cadence/release2013/setup/xyz.setup p
 Program Research license set

It works just fine! I'm perplexed. Can anyone help? If not this way, is there any other method to do this. I tried subprocess.call, however the argument cannot be passed to the file.

Here's xyz.setup even though it's definitely not a mistake in there.

#Source script for blabla
# Use an argument to determine the type 

set fl=false
set Usage = "Usage: source /imec/software/cadence/release2013/setup/blabla.csh [e|c|p|com]"

if ($# != 1) then
 echo ""
 echo "$Usage"
 echo " with:   e -> Educational research"
 echo "     c -> Cadence Academic Network (CAN)"
 echo "     p -> Program Research"
 echo "     com -> Commercial license"
 exit 1
else
 set option=$1
 set fl=true
endif

set OK = false
setenv HT `/usr/local/bin/hosttype`

switch ($HT)
 case LINUX
  switch (`uname -m`)
   case x86_64
    setenv CDS_AUTO_64BIT ALL
    set OK = true
    breaksw
   case i686
    set OK = true
    breaksw
   default:
    echo "Not the correct operating system, LINUX 64bit required (x86_64)"
    exit 1
    breaksw
  endsw
  breaksw
 default:
  echo "Not the correct operating system, LINUX 64bit required (x86_64)"
  exit 1
  breaksw
endsw


#if ($fl == true) then
  switch ($option)
    case e
      setenv xuxnxu 34234@dfsdfds3
      echo " license is set"

    case E
      setenv xuxnxu 34234@dfsdfds3
      echo " license is set"
      breaksw

    case c
      setenv xuxnxu 34234@dfsdfds3
      echo "CAN license set"
      breaksw

    case C
      setenv xuxnxu 34234@dfsdfds3
      echo "CAN license set"
      breaksw

    case p
      setenv xuxnxu 34234@dfsdfds3
      echo "Program Research license set"
      breaksw

    case P
      setenv xuxnxu 34234@dfsdfds3
      echo "Program Research license set"
      breaksw

    case com
      setenv xuxnxu 34234@dfsdfds3
      echo "Commercial license set"
      breaksw

    case COM
      setenv xuxnxu 34234@dfsdfds3
      echo "Commercial license set"
      breaksw

    default:
      set fl=false
      echo "Not the correct option specified"
      echo "$Usage"
      breaksw
  endsw
#endif



#bla bla 
setenv CDS_INST_DIR /home/software/cadence/release2013/bla bla
setenv CDS_DFII_BIN $CDS_INST_DIR/tools/dfII/bin
setenv CDS_FLEX_BIN $CDS_INST_DIR/tools/bin



set path= ($CDS_INST_DIR/tools/dfII/bin \
           $CDS_INST_DIR/tools/bin \
       /home/software/cadence/release2013/bla bla/tools/bin $path)


#echo "Cadence setup bla bla bla sourced"
  • 2
    You probably will need to provide xyz.setup. – Rinzwind Feb 17 '16 at 16:15
  • Did these countless sourcings by many people been via Python? If not, then what difference does that make? – muru Feb 17 '16 at 16:37
  • It was just to highlight the fact that the setup file being sourced does not have an error. In any case, I have added that too. – pkmanu1988 Feb 17 '16 at 16:48
  • 2
    That script quite definitely isn't bash, and it certainly doesn't fit sh. What is it? tcsh? – muru Feb 17 '16 at 16:56
  • 1
    Didn't look into it thouroughly (yet) but please, please don't use os.system. subprocess is supposed to replace it. – Jacob Vlijm Feb 17 '16 at 17:13
1

Your script is in csh syntax, however os.system calls the default shell /bin/sh. If you want your script to be properly interpreted, use

subprocess.call(['/bin/csh','-c','source /home/software/cadence/release2013/setup/xyz.setup'])
  • 2
    Probably should have -c somewhere in there (unless csh has a completely different set of options). – muru Feb 17 '16 at 19:11
  • Thank you all for the help!!! That solved it. Stupid mistake by me. – pkmanu1988 Feb 18 '16 at 10:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.