0

I source a dotcshrc file in my python script with :os.system(‘/bin/csh dotcshrc’) and it works,but when I want to use the command I have just put into the env by the source command,like os.system(‘ikvalidate mycase ‘),linux complaints:command not found. But when I do it all by hand,everything go well. Where is problem?

3
  • you should properly format your code snippets stackoverflow.com/help/formatting Commented Mar 19, 2018 at 7:16
  • sorry about that,I type all these by my phone.. Commented Mar 19, 2018 at 7:19
  • I solved this issue by submitting the task to a Perl script to get away from python os.system problem. I guess Perl use csh command,not sh command. Commented Mar 20, 2018 at 0:24

2 Answers 2

1

If you have a command in linux like ls and you want to use it in your python code do like this:

import os ls = lambda : os.system('ls') # This effectively turns that command into a python function. ls() # skadoosh! 

Output is :

FileManip.py Oscar MySafety PROJECT DOCS GooSpace Pg Admin l1_2014 PlatformMavenRepo l1_2015 R l1_201617 R64 l2_2014 Resources 
Sign up to request clarification or add additional context in comments.

1 Comment

thats pretty cool but doesn't really answer the question, and OP is already using os.system
0

os.system runs each command in its own isolated environment. If you are sourcing something in an os.system call, subsequent calls will not see that because they are starting with a fresh shell environment. If you have dependencies like the above, you might be able to combine it into one call:

os.system(‘/bin/csh "dotcshrc; ikvalidate mycase"’) 

3 Comments

This doesn’t work either,still camplains :sh :ikvalidate command not found . I thought after the source command linux should have recognized the ‘ikvalidate ‘,but it does not
its because you are using csh but os.system uses sh. You might have to enclose it in quotes to tell csh to run everything. does os.system(‘/bin/csh "dotcshrc; ikvalidate mycase"’) work?
You are right.But the .cshrc is not under my control.So I must use the Csh. I have tried subprocess,doesn’t work either.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.