2008年11月20日 星期四

2008年11月18日 星期二

[Python code] 執行shell或program中的commands

1) The standard way of executing an application without capturing its output is to use the call function:

from subprocess import call
try:
returncode = call(cmd, shell=True)
if returncode:
print 'Failure with returncode', returncode; sys.exit(1)
except OSError, message:
print 'Execution failed! \n', message; sys.exit(1)

2) 使用Popen object:
例子如下 ----
from subprocess import Popen, PIPE
cmd = 'myprog -c file.1 -p <>
p = Popen(cmd, shell=True, stdout=PIPE)
output, errors = p.communicate()

另一個例子是在程式中使用 (ex. SPIDER這種interactive的program) ----
pipe = Popen('gnuplot -persist', shell=True, stdin=PIPE).stdin
pipe.write('set xrange [0:10]; set yrange [-2:2]\n')
pipe.write('plot sin(x)\n')
pipe.write(quit') # quit Gnuplot

2008年11月16日 星期日

[Python code] Run commands in shell

import commands
cmd = 'programName < %s.i' % case # command to run
failure, output = commands.getstatusoutput(cmd)
if failure:
print 'Running the programName code failed\n%s\n%s' % (cmd, output)
sys.exit(1)

[Python code] Create a subdirectory

import os, shutil
d = case # name of the subdirectory
if os.path.isdir(d): # does d exist?
shutil.rmtree(d) # yes, then remove the old directory
os.mkdir(d) # make a new directory
os.chdir(d) # change to new directory

2008年11月3日 星期一

Compiling 2dx source in Ubuntu on 11/04/2008

1. 改mrcHeaderDisplay中的member function "setHeader"
2. 在fftlib.cpp中, strcpy和getenv需要include string.h和stdlib.h

2008年11月2日 星期日

How to uncompress a file with tar?

Commands:
tar xzvf ****.tar.gz
tar xvjf ****.tar.bz2
tar xvf ****.tar

x = eXtract
v = Verbose (optional) the files with relative locations will be displayed
z = gZipped; j = bzip2-zipped
f = from/to file