I have a python script, changeDates.py, that successfully runs outside of a C# program started in the cmd by the command:
python changeDates.py path/to/folder numberOfMonths numberOfWeeks testSetsToCheck
These arguments are all strings. the numberOfMonths and numberOfWeeks is passed to the python script as a string then converted inside the script to an int.
But if i were to run the same command using:
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);
}
}
The script starts and outputs the following error:
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
Why would the regex in the python suddenly result in an error? How can I fix this?