1

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?

2
  • Bad arguments? Maybe you quote the wrong thing -- in Windows quotes are special, special things. Different permissions? In VS you probably have administrative access, while outside you most likely don't. I mean we're just guessing here, need more info! Commented Mar 17, 2015 at 21:31
  • I don't know how I could get more information... Commented Mar 17, 2015 at 22:07

1 Answer 1

1

The string argument that you have passed to your re.search function is a python module and when you execute your python code in that way the variable string doesn't assigned correctly! So, first of all, don't use python key words and built-in names as your variable names and, to get rid of this situation, you need to check the way that you assigned the string within your code!

Sign up to request clarification or add additional context in comments.

5 Comments

I don't see how it could be an issue with the python code. since I was able to run the python script successfully in the cmd and through java. Ill check it though.
@user2853442 i said that when you execute your code with c# the string couldn't been assigned correctly! did you pass any argument to your script with c#?
Oh sorry I misunderstood. I will edit my question with the arguments.
I did use arguments all of which were passed as a string to the python script.
@user2853442 im not familiar with c#, you need to check the way that you pass numberOfMonths numberOfWeeks testSetsToCheck to your python script!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.