【发布时间】:2015-03-17 21:26:05
【问题描述】:
我有一个 python 脚本,changeDates.py,它成功地在一个 C# 程序之外运行,该程序通过以下命令在 cmd 中启动:
python changeDates.py path/to/folder numberOfMonths numberOfWeeks testSetsToCheck
这些参数都是字符串。 numberOfMonths 和 numberOfWeeks 作为字符串传递给 python 脚本,然后在脚本内部转换为 int。
但如果我要使用以下命令运行相同的命令:
private void run_CMD(string cmd, string args, bool messageBox)
{
try
{
Console.WriteLine(cmd);
Console.WriteLine(args);
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = cmd;
start.Arguments = args;
start.UseShellExecute = false;
start.RedirectStandardOutput = true;
using (Process process = Process.Start(start))
{
using (StreamReader reader = process.StandardOutput)
{
string result = reader.ReadToEnd();
Console.Write(result);
}
}
}
catch (Exception ex)
{
Console.WriteLine("Error while trying to check package dates: \n" + ex);
Logger.Write(Logger.Level.ERROR, "Error while trying to check package dates: \n" + ex);
}
}
脚本启动并输出以下错误:
C:\Users\bblashko\Documents\VisualStudio2012\Projects\Athena_Test_Automation_Fr
amework\Athena_Test_Automation_Framework\scripts\changeDates.py C:\Users\bblashk
o\Documents\VisualStudio2012\Projects\Athena_Test_Automation_Framework\Athena_Te
st_Automation_Framework\Test_Cases 6 1 00100
Traceback (most recent call last):
File "C:\Users\bblashko\Documents\VisualStudio2012\Projects\Athena_Test_Automa
tion_Framework\Athena_Test_Automation_Framework\scripts\changeDates.py", line 51
0, in <module>
allFiles = checkContent(content, subDir, int(sys.argv[2]), int(sys.argv[3]))
File "C:\Users\bblashko\Documents\VisualStudio2012\Projects\Athena_Test_Automa
tion_Framework\Athena_Test_Automation_Framework\scripts\changeDates.py", line 47
, in checkContent
checkXLSX(f, subDir, numberOfMonths, numberOfWeeks)
File "C:\Users\bblashko\Documents\VisualStudio2012\Projects\Athena_Test_Automa
tion_Framework\Athena_Test_Automation_Framework\scripts\changeDates.py", line 85
, in checkXLSX
changeDate = checkXLSXDates(salesStartDate, pubDate, type, todaysDate, check
Date)
File "C:\Users\bblashko\Documents\VisualStudio2012\Projects\Athena_Test_Automa
tion_Framework\Athena_Test_Automation_Framework\scripts\changeDates.py", line 15
7, in checkXLSXDates
if(re.search("(\w\w)/(\w\w)/(\w\w\w\w)", salesStartDate) and re.search("(\w\
w)/(\w\w)/(\w\w\w\w)", pubDate)):
File "C:\Python34\lib\re.py", line 166, in search
return _compile(pattern, flags).search(string)
TypeError: expected string or buffer
为什么python中的正则表达式会突然出错? 我该如何解决这个问题?
【问题讨论】:
-
错误的论点?也许你引用了错误的东西——在 Windows 中,引号是特殊的、特殊的东西。不同的权限?在 VS 中,您可能具有管理权限,而在外部您很可能没有。我的意思是我们只是在这里猜测,需要更多信息!
-
我不知道如何获得更多信息...