[英]Run c scrips from a shell script
I have this shell script 我有这个shell脚本
#!/bin/csh
@ x = 1
while ($x <= 2)
nohup ./prog1 && ./prog2 &
@ x ++
end
I want to run sequentially for 2 times prog1 and prog2 that are previously compiled trough a makefile. 我想按顺序运行2次prog1和prog2,这些都是先前通过makefile编译的。 How can I do it? 我该怎么做? Is the script right? 脚本是对的吗?
If I do 如果我做
chmod u+x test.csh
./test.csh
I get this error 我收到这个错误
./prog1: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.11' not found (required by ./prog1)
This is my makefile 这是我的makefile
GSLFLAGS := `pkg-config --cflags gsl`
LIBGSL := `pkg-config --libs gsl`
CFLAGS = -O3 -fopenmp
LIBOMP = -lgomp
dist.o:dist.cxx
g++ -Wall -c dist.cxx
prog1.o:prog1.cxx
g++ -Wall -c prog1.cxx $< ${GSLFLAGS} ${CFLAGS}
prog1:prog1.o dist.o
g++ ${CFLAGS} -o $@ $^ ${LIBGSL}
prog2.o:prog2.cxx
g++ -Wall -c prog2.cxx $< ${GSLFLAGS} ${CFLAGS}
prog2:prog2.o dist.o
g++ ${CFLAGS} -o $@ $^ ${LIBGSL}
It appears that the search path for the standard C++ library is set differently in csh vs. when you run from the command line. 看起来标准C ++库的搜索路径在csh中与从命令行运行时的设置不同。
Linking the standard libraries statically should make the library search path irrelevant: change your makefile as follows: 静态链接标准库应该使库搜索路径无关紧要:更改makefile,如下所示:
CFLAGS = -O3 -fopenmp -static-libgcc -static-libstdc++
If you really want to do what you ask, use this: 如果你真的想做你要求的,请使用:
#!/bin/csh
./prog1
./prog2
./prog1
./prog2
I sense you are confused by backgrounding process and the like. 我觉得你对背景过程等感到困惑。
Run prog1 then prog2 if prog1 exits successfully: 如果prog1成功退出,则运行prog1然后prog2:
./prog1 && ./prog2
Run prog1 and then prog2 regardless: 无论如何运行prog1然后prog2:
./prog1; ./prog2
Run prog1 in the background: 在后台运行prog1:
./prog1 &
Sleep 8 seconds then ring bell, but give me back my prompt immediately: 睡8秒钟然后响铃,但立即回复我的提示:
(sleep 3; sleep 5;echo $'\a') &
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.