Python script not processing files

Page 1 of 3 123 LastLast

  1. Posts : 118
    Win 7 Ultimate x32, x64, Win 7 Pro x32, x64 Win 7 Home x64, XP Pro sp3
       #1

    Python script not processing files


    I'm trying to run a python script on a secure folder. The script is running. I don't think (although I don't know for sure) that the script is reading the files.

    Running as Administrator
    The folder permissions and all sub folders/files is:
    Administrator (Full Control)
    Owner Administrator

    Running in Win7 sp1

    Batch file:
    Code:
    cd "C:\Programs\CommuniGate Files\SystemLogs"
    Call "C:\Batch\CGPLogSummary.py" 
    cmd
    The python script is supposed to read files, Process the files, and send an email with the results.
    The script does send the email but the results are not in the email.

    Does anyone know what I can do to figure out what is wrong?

    Thanks,

    Docfxit
      My Computer


  2. Posts : 5,092
    Windows 7 32 bit
       #2

    Could you post the Python script?
      My Computer


  3. Posts : 118
    Win 7 Ultimate x32, x64, Win 7 Pro x32, x64 Win 7 Home x64, XP Pro sp3
    Thread Starter
       #3

    The first part is at:
    pastebin.ws 2.1 - Reading paste 7ipf3
    The second part is at:
    pastebin.ws 2.1 - Reading paste 2fuu3n

    It was too large to post in one pastebin.

    I am running it in Python 3.2.2
    Win7

    Thank you for taking a look at it.

    Docfxit
      My Computer


  4. Posts : 5,092
    Windows 7 32 bit
       #4

    And when it runs you are on a remote machine so you can't see any error messages?

    On Windows whenever I see file paths with spaces, like somevar = "C:\Program Files\yada yada\some.exe"

    I look for an error due to the file path being chopped off at the first space like "C:\Program is not a valid path" since spaces are used as a separator on the command line. Worst thing that ever happened to Windows. I bet it accounts for more than 80% of programming bugs with files.
      My Computer


  5. Posts : 118
    Win 7 Ultimate x32, x64, Win 7 Pro x32, x64 Win 7 Home x64, XP Pro sp3
    Thread Starter
       #5

    MilesAhead said:
    And when it runs you are on a remote machine so you can't see any error messages?

    On Windows whenever I see file paths with spaces, like somevar = "C:\Program Files\yada yada\some.exe"

    I look for an error due to the file path being chopped off at the first space like "C:\Program is not a valid path" since spaces are used as a separator on the command line. Worst thing that ever happened to Windows. I bet it accounts for more than 80% of programming bugs with files.
    Thanks for looking at it.

    I am on the local machine when this is run.

    I'm not seeing any errors when it's run. I'm running it from a bat file.
    Is there something I can put into the script to test the success or failure of the path access?

    Thank you,

    Docfxit
      My Computer


  6. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #6

    Hi, excuse my abrupt entrance to this thread,

    When asking for help on a script, it's probably a good idea to post the script or at least provide snippets of it. It's difficult to help people with problems such as "My script isn't working, I don't know what the problem is, please help me".

    If you expect decent help you must be specific about your problem... Are there any error messages? Or does the script simply hang (no output whatsoever)? You should make some attempt to find out (more information about) the problem prior to resorting to a help forum. You should post any findings you feel are necessary to help others assist you in your problem.


    With that out of the way, Docfxit, I have recovered your Python script from the Pastebin links you've given and have reposted your script in a zipped file (attached to this post) for the sole convenience of others, should they be able to help you.

    I've examined the Python script, and just as MilesAhead suspected, there are immediate errors with your paths (but hardly to do with spaces); they are entered incorrectly in a Python script nonetheless. I assume you've entered these values yourself, Docfxit.

    Code:
    logdir = "C:\Programs\CommuniGate Files\SystemLogs\"
    submitdir = "C:\Programs\CommuniGate Files\Submitted\"
    Two things wrong with the above here.

    First of all, specifying a folder path with a trailing backslash is considered incorrect. And this is anywhere in Windows. Try not to add an excess backslash to the end of paths, ever.

    Secondly, in Python strings, a backslash is an escape character (a.k.a EOL character). If you want to use a literal backslash, you must escape it by backslash-ing the backslash.
    E.g. logdir = "C:\\Programs\\CommuniGate Files\\SystemLogs"

    Alternately, you could specify to Python a raw string (or literal string) where each character in the string is interpreted literally. Do this by appending an 'r' to the start of a string.
    E.g. logdir = r"C:\Programs\CommuniGate Files\SystemLogs"


    Lastly, there is a very minor syntax error on line 904, where
    Code:
    outstring += (val + ":").ljust(stats_len + 2) +
    should have an EOL (end of line) character on the end of the line. For instance:
    Code:
    outstring += (val + ":").ljust(stats_len + 2) + \
    The EOL character is need on the end here because this line of Python code continues on the next line. I have no idea why it is missing one.


    It is up to you, Doc., to find and fix these three bad lines (hint: 10, 11, 904).


    On a side note, your Batch file, you should be using the 'pause' command instead of 'cmd' if you want to view the scripts' output. (pause halts script execution until a keypress.)
    Python script not processing files Attached Files
      My Computer


  7. Posts : 5,092
    Windows 7 32 bit
       #7

    It's been a very long time since I played with Python. Pyprohly points out that the backslash is an escape similar to C based languages.

    A good idea is to make tiny test scripts to find out if a particular thing is working as expected. For instance assigning the path to a variable then prining it out to the console to see the output.

    There are many Python programmers on Windows so it may be a good idea to post questions in a Python forum. Instead of guys like me who have forgotten most of their Python you would have your question read by Python programmers current in the language. I think the last time I wrote a script Python was in version 2.x :)
      My Computer


  8. Posts : 118
    Win 7 Ultimate x32, x64, Win 7 Pro x32, x64 Win 7 Home x64, XP Pro sp3
    Thread Starter
       #8

    Thank you very much for jumping in and explaining everything in detail for me.

    Pyprohly said:
    Hi, excuse my abrupt entrance to this thread,

    When asking for help on a script, it's probably a good idea to post the script or at least provide snippets of it. It's difficult to help people with problems such as "My script isn't working, I don't know what the problem is, please help me".
    I'm sorry I didn't include enough information.

    Pyprohly said:
    If you expect decent help you must be specific about your problem... Are there any error messages? Or does the script simply hang (no output whatsoever)? You should make some attempt to find out (more information about) the problem prior to resorting to a help forum. You should post any findings you feel are necessary to help others assist you in your problem.
    I will try to give more information next time.

    Pyprohly said:
    With that out of the way, Docfxit, I have recovered your Python script from the Pastebin links you've given and have reposted your script in a zipped file (attached to this post) for the sole convenience of others, should they be able to help you.
    Thank you for including it in this post correctly.

    Pyprohly said:
    I've examined the Python script, and just as MilesAhead suspected, there are immediate errors with your paths (but hardly to do with spaces); they are entered incorrectly in a Python script nonetheless. I assume you've entered these values yourself, Docfxit.

    Code:
    logdir = "C:\Programs\CommuniGate Files\SystemLogs\"
    submitdir = "C:\Programs\CommuniGate Files\Submitted\"
    Two things wrong with the above here.

    First of all, specifying a folder path with a trailing backslash is considered incorrect. And this is anywhere in Windows. Try not to add an excess backslash to the end of paths, ever.
    I agree with you 100%. This is a script I acquired from someone else and I am not familiar with Python.
    I have removed the trailing backslash from both strings. I am now getting an error when I run the script.
    Error: [Errno 2] No such file or directory: 'C:\\Programs\\CommuniGate Files\\Sy
    stemLogs2014-12-05.log'

    There should be a backslash between the "s" and the "2". Since it is not a good practice to have a trailing backslash it would be great if you could please help me by suggesting how to code that backslash in the script.

    Pyprohly said:
    Secondly, in Python strings, a backslash is an escape character (a.k.a EOL character). If you want to use a literal backslash, you must escape it by backslash-ing the backslash.
    E.g. logdir = "C:\\Programs\\CommuniGate Files\\SystemLogs"
    In the original script it did have a double backslash. For some reason it must have been dropped when I posted it in Pastebin.

    Pyprohly said:
    Alternately, you could specify to Python a raw string (or literal string) where each character in the string is interpreted literally. Do this by appending an 'r' to the start of a string.
    E.g. logdir = r"C:\Programs\CommuniGate Files\SystemLogs"


    Lastly, there is a very minor syntax error on line 904, where
    Code:
    outstring += (val + ":").ljust(stats_len + 2) +
    should have an EOL (end of line) character on the end of the line. For instance:
    Code:
    outstring += (val + ":").ljust(stats_len + 2) + \
    The EOL character is need on the end here because this line of Python code continues on the next line. I have no idea why it is missing one.
    In the original script it did have a backslash. For some reason it must have been dropped when I posted it in Pastebin.

    Pyprohly said:

    It is up to you, Doc., to find and fix these three bad lines (hint: 10, 11, 904).


    On a side note, your Batch file, you should be using the 'pause' command instead of 'cmd' if you want to view the scripts' output. (pause halts script execution until a keypress.)
    Thank you very much. That is great of you to help so much.

    If you could let me know how/where to code the slash between the path and the file name that would be wonderful.

    Thanks a bunch,

    Docfxit
      My Computer


  9. Posts : 5,092
    Windows 7 32 bit
       #9

    I should have posted a link to get you started:
    https://www.python.org/about/help/
      My Computer


  10. Posts : 118
    Win 7 Ultimate x32, x64, Win 7 Pro x32, x64 Win 7 Home x64, XP Pro sp3
    Thread Starter
       #10

    Thank you for the link.

    For the temporary moment I added the backslash backslash back in to get it running.

    I ran the script. I am getting the email that the script sends with the dates. It's not including the data in the email that it's supposed to send. I am not getting any error messages.

    Thanks,

    Docfxit
      My Computer


 
Page 1 of 3 123 LastLast

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 10:54.
Find Us