我可以使用Shell或Python实现调用C程序并给出它所需的所有参数吗?

我可以使用Shell或Python实现调用C程序并给出它所需的所有参数吗?,python,shell,automation,Python,Shell,Automation,我遇到了一个问题,我不知道这是否可以在像Bash或Python这样的Shell中实现 我需要运行一个C程序多次,该程序是TEM图像模拟的“atompot”。如果我运行这个程序 ./atompot 其输出如下: atompot version dated 8-oct-2012 EJK Copyright (C) 1998-2010 Earl J. Kirkland This program is provided AS-IS with ABSOLUTELY NO WARRANTY under t

我遇到了一个问题,我不知道这是否可以在像Bash或Python这样的Shell中实现

我需要运行一个C程序多次,该程序是TEM图像模拟的“atompot”。如果我运行这个程序

./atompot
其输出如下:

atompot version dated 8-oct-2012 EJK
Copyright (C) 1998-2010 Earl J. Kirkland
This program is provided AS-IS with ABSOLUTELY NO WARRANTY
under the GNU general public license

calculate projected atomic potentials (to use in multislice)
using FFTW

Name of file with input crystal data :
echo -e 'stra.dat\nstraa.tif\n...' | ./atompot
然后我需要输入crtstal数据文件,如下所示:

stra.dat
然后你可以得到:

Name of file to get binary output of atomic potential :
然后我给这个名字:

straa.tif   
然后你会得到:

Real space dimensions in pixels Nx, Ny :
你的回答是:

512 512
然后输出如下所示:

 Replicate unit cell by NCELLX,NCELLY,NCELLZ :
答复:

  8 8 8
  n
询问:

答复:

  8 8 8
  n
程序是这样的。 我可以使用Shell或Python实现调用C程序,并提供使程序自动运行所需的所有参数吗

例如,我可以将单位单元格形式8更改为100。 并保持其他参数不变。似乎所有这些都可以在一个Sheel脚本中完成,但是如何实现一些C程序,为您提供输入内容的指令


谢谢大家!

如果程序从stdin读取,只需将所有内容放入一个文件:

stra.dat
straa.tif
512 512
8 8 8
n
跑步:

./atompot < filename
/atompot

如果您想做一些更复杂的事情(即解析输出或实现分支),可以查看python中的subprocess.Popen。

如果程序从stdin读取,只需将所有内容都放在一个文件中:

stra.dat
straa.tif
512 512
8 8 8
n
跑步:

./atompot < filename
/atompot

如果您想做一些更复杂的事情(即解析输出或实现分支),可以查看python中的subprocess.Popen。

您可以制作如下shell脚本:

atompot version dated 8-oct-2012 EJK
Copyright (C) 1998-2010 Earl J. Kirkland
This program is provided AS-IS with ABSOLUTELY NO WARRANTY
under the GNU general public license

calculate projected atomic potentials (to use in multislice)
using FFTW

Name of file with input crystal data :
echo -e 'stra.dat\nstraa.tif\n...' | ./atompot

要获得更多控制,您可能需要查看。

您可以制作如下shell脚本:

atompot version dated 8-oct-2012 EJK
Copyright (C) 1998-2010 Earl J. Kirkland
This program is provided AS-IS with ABSOLUTELY NO WARRANTY
under the GNU general public license

calculate projected atomic potentials (to use in multislice)
using FFTW

Name of file with input crystal data :
echo -e 'stra.dat\nstraa.tif\n...' | ./atompot

要获得更多控制,您可能需要查看。

是的!谢谢你的建议。那真的很有用!是的!谢谢你的建议。那真的很有用!