Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Python script not processing files

03 Dec 2014   #1
Docfxit

Win 7 Ultimate x32, x64, Win 7 Pro x32, x64 Win 7 Home x64, XP Pro sp3
 
 
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 System SpecsSystem Spec
.
05 Dec 2014   #2
MilesAhead

Windows 7 32 bit
 
 

Could you post the Python script?
My System SpecsSystem Spec
05 Dec 2014   #3
Docfxit

Win 7 Ultimate x32, x64, Win 7 Pro x32, x64 Win 7 Home x64, XP Pro sp3
 
 

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 System SpecsSystem Spec
.

05 Dec 2014   #4
MilesAhead

Windows 7 32 bit
 
 

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 System SpecsSystem Spec
05 Dec 2014   #5
Docfxit

Win 7 Ultimate x32, x64, Win 7 Pro x32, x64 Win 7 Home x64, XP Pro sp3
 
 

Quote   Quote: Originally Posted by MilesAhead View Post
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 System SpecsSystem Spec
06 Dec 2014   #6
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

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.)


Attached Files
File Type: zip THREAD-354148_mail.py.zip (9.4 KB, 0 views)
My System SpecsSystem Spec
06 Dec 2014   #7
MilesAhead

Windows 7 32 bit
 
 

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 System SpecsSystem Spec
06 Dec 2014   #8
Docfxit

Win 7 Ultimate x32, x64, Win 7 Pro x32, x64 Win 7 Home x64, XP Pro sp3
 
 

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

Quote   Quote: Originally Posted by Pyprohly View Post
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.

Quote   Quote: Originally Posted by Pyprohly View Post
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.

Quote   Quote: Originally Posted by Pyprohly View Post
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.

Quote   Quote: Originally Posted by Pyprohly View Post
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.

Quote   Quote: Originally Posted by Pyprohly View Post
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.

Quote   Quote: Originally Posted by Pyprohly View Post
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.

Quote   Quote: Originally Posted by Pyprohly View Post

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 System SpecsSystem Spec
06 Dec 2014   #9
MilesAhead

Windows 7 32 bit
 
 

I should have posted a link to get you started:
https://www.python.org/about/help/
My System SpecsSystem Spec
06 Dec 2014   #10
Docfxit

Win 7 Ultimate x32, x64, Win 7 Pro x32, x64 Win 7 Home x64, XP Pro sp3
 
 

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 System SpecsSystem Spec
Reply

 Python script not processing files




Thread Tools Search this Thread
Search this Thread:

Advanced Search




Similar help and support threads
Thread Forum
VB script: Rename all files in a folder to a specified prefix
Hi, I'm trying to find help in entering paths and prefix's in my vb script. I am of course a newbie to visual basic and don't know where to enter the path and wording for prefix. Any help would be most appreciated. Rich
General Discussion
Excel 2013 - Processor overheats when processing large files
Hello, I have a very rare issue here. I'm trying to convert a normal xlsx file into a csv file. In the xlsx file there are normal columns and rows, nothing strange, nor formatting or something pretty, only colums and rows with products plain information. I've received these files via...
Microsoft Office
Script help - downloading files from multiple computers
Hi all, So i am new to scripting and I am having issues figuring out where to start. Hope someone can help. I have 20+ computers that I connect to and grab .txt files. I would like to create a bat file that will connect to the computers and download the files to my local. This will save me...
General Discussion
How to script a daily copy of files w/dt being name of archive folder
Hello, I need to figure out a Windows 7 script to copy/archive files which are located in a specific folder. It needs to copy daily to an archive folder, with the script creating the archive folder as MM-DD-YY (being that day's date that is being archived) before it archives the files to that...
General Discussion
A script to automate moving files off C: prior to backup?
I back up my files and system image weekly. I move the recorded TV shows (broadcast TV, nothing illegal) before that from my hard drive onto an external drive. Another drive in the same cabinet does the backup. It saves time and I won't want those files after a disc failure anyway. It would be...
General Discussion
looking for cmd script to unhide files
at one point i had a virus on a thumbdrive, it would hide all the files in it and say it was un usable data, if you said view hidden files, they would all appear. i had figured out a dll to run in cmd that would unhide the files that where not meant to be hidden such as windows .trashes etc. i had...
System Security


Our Sites

Site Links

About Us

Find 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 03:24.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App