我有一个Bash脚本,它构建一个字符串以作为命令运行
脚本:
#! /bin/bash
matchdir="/home/joao/robocup/runner_workdir/matches/testmatch/"
teamAComm="`pwd`/a.sh"
teamBComm="`pwd`/b.sh"
include="`pwd`/server_official.conf"
serverbin='/usr/local/bin/rcssserver'
cd $matchdir
illcommando="$serverbin include='$include' server::team_l_start = '${teamAComm}' server::team_r_start = '${teamBComm}' CSVSaver::save='true' CSVSaver::filename = 'out.csv'"
echo "running: $illcommando"
# $illcommando > server-output.log 2> server-error.log
$illcommando
Run Code Online (Sandbox Code Playgroud)
这似乎没有正确地提供参数$serverbin
.
脚本输出:
running: /usr/local/bin/rcssserver include='/home/joao/robocup/runner_workdir/server_official.conf' server::team_l_start = '/home/joao/robocup/runner_workdir/a.sh' server::team_r_start = '/home/joao/robocup/runner_workdir/b.sh' CSVSaver::save='true' CSVSaver::filename = 'out.csv'
rcssserver-14.0.1
Copyright (C) 1995, 1996, 1997, 1998, 1999 Electrotechnical Laboratory.
2000 - 2009 RoboCup Soccer Simulator Maintenance Group.
Usage: /usr/local/bin/rcssserver [[-[-]]namespace::option=value]
[[-[-]][namespace::]help]
[[-[-]]include=file]
Options:
help
display generic help
include=file
parse …
Run Code Online (Sandbox Code Playgroud) 我正在开发一个项目,需要一个配置文件,其数据由多个模块使用.
我的问题是:通用方法是什么?我应该从每个模块(文件)中读取配置文件还是有其他方法可以做到这一点?
我想有一个名为config.py的模块,它读取配置文件,每当我需要配置时,我会import config
做一些事情,比如config.data['teamsdir']
获取'teamsdir'
属性(例如).
响应:选择conf.py方法,因为它是模块化的,灵活的和简单的
我可以直接将配置数据放在文件中,后者如果我想从json文件读取一个xml文件或多个源我只需更改conf.py并确保以相同的方式访问数据.
接受答案:选择"Alex Martelli"的回应是因为它是最完整的.投票给其他答案,因为它们也很好,也很有用.
有时我需要确定某个整数是偶数.因此我可以使用以下代码:
int number = /* magic initialization here */;
// make sure the number is even
if ( number % 2 != 0 ) {
number--;
}
Run Code Online (Sandbox Code Playgroud)
但这似乎并没有被非常有效的最有效的方式做到这一点,所以我可以做到以下几点:
int number = /* magic initialization here */;
// make sure the number is even
number &= ~1;
Run Code Online (Sandbox Code Playgroud)
但(除了不可读)我不确定该解决方案是否完全可移植.
注意:此代码应该只适用于正整数,但有一个解决方案也适用于负数将是一个加号.
我需要一个Bash(或一个普通的shell)脚本来放入一个cronjob,每分钟检查一下Internet是否正常运行.
我就这样做了:
#! /bin/sh
host1=google.com
host2=wikipedia.org
curr_date=`date +"%Y%m%d%H%M"`
echo -n "${curr_date};"
((ping -w5 -c3 $host1 || ping -w5 -c3 $host2) > /dev/null 2>&1) &&
echo "up" || (echo "down" && exit 1)
Run Code Online (Sandbox Code Playgroud)
你会怎么做?你会ping哪个主机?
澄清:
通过" 互联网上升 ",我的意思是我的互联网连接.
通过" up ",我的意思是拥有可用的连接(如果我们正在谈论DNS正在关闭或者连接真的很慢,那么这并不重要[请注意-w
超时]).这也是我没有包含任何IP而只包含主机的原因.
我还应该ping Stack Overflow吗?我的意思是,如果我无法访问谷歌,维基百科或Stack Overflow,我不想要互联网:p
我正在编写一个bash脚本,需要将运行的命令的输出stdout
和stderr
输出重定向到单个文件,并在每个行前面加上stderr
或者stdout
相应的前缀.
有一个简单的方法来做到这一点?
在openUrl:
启动应该回调我的应用程序的应用程序之前(就像根据x-callback-url规范行事的应用程序),在调用其他应用程序之前,如何以编程方式检查我的应用程序回调是否正常?
我的一个朋友写了这个小程序.这textFile
是1.2GB的大小(7年的报纸).他成功地设法创建了字典,但他不能使用pickle(程序挂起)将其写入文件.
import sys
import string
import cPickle as pickle
biGramDict = {}
textFile = open(str(sys.argv[1]), 'r')
biGramDictFile = open(str(sys.argv[2]), 'w')
for line in textFile:
if (line.find('<s>')!=-1):
old = None
for line2 in textFile:
if (line2.find('</s>')!=-1):
break
else:
line2=line2.strip()
if line2 not in string.punctuation:
if old != None:
if old not in biGramDict:
biGramDict[old] = {}
if line2 not in biGramDict[old]:
biGramDict[old][line2] = 0
biGramDict[old][line2]+=1
old=line2
textFile.close()
print "going to pickle..."
pickle.dump(biGramDict, biGramDictFile,2)
print "pickle done. now load it..." …
Run Code Online (Sandbox Code Playgroud) 在android上使用java原生界面时,我犯了两个愚蠢的错误,花了我很多时间.
有这个方法id:
jmethodID myMethod_methodID = env->GetMethodID(hello_Cls, "myMethod", "(ILjava/lang/String;Ljava/lang/String;I)Z");
Run Code Online (Sandbox Code Playgroud)
我的第一个错误是使用它
env->CallVoidMethod
Run Code Online (Sandbox Code Playgroud)
而我的第二个错误是这样称呼它
jboolean rv = jenv->CallBooleanMethod(hello_obj, myMethod_methodID, myfirst_jstring, mysecond_jstring, 1);
Run Code Online (Sandbox Code Playgroud)
这显然错过了和jint
之间的争论.myMethod_methodID
myfirst_jstring
我花了很长时间来跟踪这些错误,因为logcat中没有相关的输出,唯一的行为是没有做任何事情(它甚至没有崩溃).
所以,问题是:如何为这类错误获得更有意义的错误?
我的问题很简单,下一个代码是安全的吗?
struct Parent {
B* _a;
Parent(B* a) : _a(a) {}
};
struct Child : public Parent {
B _b;
Child() : Parent(&_b), _b(2){};
};
int main() {
Child c;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
还有两点:
_b
将分配(及其内存地址),并且无论我使用哪个编译器,此代码都将起作用.提前致谢.
通过安全澄清我实际上意味着内存地址是有效的,因为我已经知道它没有被初始化.
其他说明
在我的实际代码中,我想将类型的对象存储B
为其基类的指针A
,如下所示:
struct Parent {
A* _a;
Parent(A* a) : _a(a) {}
};
struct Child : public Parent {
B _b;
Child() : Parent(&_b), _b(2){};
};
int main() {
Child c;
return 0;
} …
Run Code Online (Sandbox Code Playgroud) 我将用于nunit-console
在我的解决方案中运行所有测试.
我这样做了:
c:\some\path>nunit-console-x86.exe MySolution.sln
NUnit-Console version 2.6.2.12296
Copyright (C) 2002-2012 Charlie Poole.
Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov.
Copyright (C) 2000-2002 Philip Craig.
All Rights Reserved.
Runtime Environment -
OS Version: Microsoft Windows NT 6.1.7601 Service Pack 1
CLR Version: 2.0.50727.5466 ( Net 3.5 )
ProcessModel: Default DomainUsage: Default
Execution Runtime: net-3.5
Could not load file or assembly 'MyNamespace.Administration, Version=0.0.0.1, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the …
Run Code Online (Sandbox Code Playgroud)