[Beginner] Hanging in the code until I press return, can't figure it out

2016-04-02 Thread Loop.IO
Hey

So I built a keylogger using python as a test, got the code from the tutorial 
online, I want to improve on it to make it more automated, but the issue I'm 
having is it won't create the file until I press return, any clues where I'm 
going wrong?

If I press return it makes the batch file, otherwise it just hangs.

CODE:

import os
from os.path import join

lookfor = "iexplore.exe"
for root, dirs, files in os.walk('C:\\Program Files\\Internet Explorer'):
print "searching", root
if lookfor in files:
print "found: %s" % join(root, lookfor)

import sys

def create():
print("creating new file")

name=raw_input ('C:\\Documents\\PythonCoding\\')+'launch2.bat'


try:
file=open(name,'w')
file.close()

except:
print("error occured")
sys.exit(0)

create()
-- 
https://mail.python.org/mailman/listinfo/python-list


[Beginner] - Hanging in the code, can't figure out what's wrong

2016-04-02 Thread Loop.IO
Hey 

So I built a keylogger using python as a test, got the code from the tutorial 
online, I want to improve on it to make it more automated, but the issue I'm 
having is it won't create the file until I press return, any clues where I'm 
going wrong? 

If I press return it makes the batch file, otherwise it just hangs. 

CODE: 

import os 
from os.path import join 

lookfor = "iexplore.exe" 
for root, dirs, files in os.walk('C:\\Program Files\\Internet Explorer'): 
print "searching", root 
if lookfor in files: 
print "found: %s" % join(root, lookfor) 
 
import sys 

def create(): 
print("creating new file") 

name=raw_input ('C:\\Documents\\PythonCoding\\')+'launch2.bat' 


try: 
file=open(name,'w') 
file.close() 

except: 
print("error occured") 
sys.exit(0) 

create() 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Beginner] - Hanging in the code, can't figure out what's wrong

2016-04-02 Thread Loop.IO
On Saturday, April 2, 2016 at 11:09:13 PM UTC+1, BartC wrote:
> On 02/04/2016 22:59, Loop.IO wrote:
> > Hey
> >
> > So I built a keylogger using python as a test, got the code from the 
> > tutorial online, I want to improve on it to make it more automated, but the 
> > issue I'm having is it won't create the file until I press return, any 
> > clues where I'm going wrong?
> >
> > If I press return it makes the batch file, otherwise it just hangs.
> 
> >  name=raw_input ('C:\\Documents\\PythonCoding\\')+'launch2.bat'
> 
> You're asking for a file name to be entered. So that if ABC is pressed, 
> followed by Enter, it will use:
> 
>C:\Documents\PythonCoding\ABClaunch2.bat
> 
> Assuming that's the intention, then Enter is needed so that it knows 
> when the user has completed typing the name. If not, then just use:
> 
>name='C:\\Documents\\PythonCoding\\launch2.bat'
> 
> (If you want a single character name, without pressing Enter, that's 
> harder to do. Someone else will have to help.)
> 
> -- 
> Bartc

Hey Bartc

I don't quite understand what you mean?

The file is just supposed to be created, I don't want to have to press "Enter" 
or "Return" for it to complete the file creation

the info i followed to create the file advised I had to add the file name and 
extension on after like in the code
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Beginner] - Hanging in the code, can't figure out what's wrong

2016-04-02 Thread Loop.IO
On Saturday, April 2, 2016 at 11:27:49 PM UTC+1, BartC wrote:
> On 02/04/2016 23:16, Ned Batchelder wrote:
> > On Saturday, April 2, 2016 at 6:09:13 PM UTC-4, BartC wrote:
> >> On 02/04/2016 22:59, Loop.IO wrote:
> >>> Hey
> >>>
> >>> So I built a keylogger using python as a test, got the code from the 
> >>> tutorial online, I want to improve on it to make it more automated, but 
> >>> the issue I'm having is it won't create the file until I press return, 
> >>> any clues where I'm going wrong?
> >>>
> >>> If I press return it makes the batch file, otherwise it just hangs.
> >>
> >>>   name=raw_input ('C:\\Documents\\PythonCoding\\')+'launch2.bat'
> >>
> >> You're asking for a file name to be entered. So that if ABC is pressed,
> >> followed by Enter, it will use:
> >>
> >> C:\Documents\PythonCoding\ABClaunch2.bat
> >
> > That line of code will prompt the user:
> >
> >  C:\Documents\PythonCoding\
> >
> > then the user enters ABC:
> >
> >  C:\Documents\PythonCoding\ABC
> >
> > and raw_input returns "ABC", so name becomes "ABClaunch2.bat".
> 
> Yes, of course. I ran the code and picked up the wrong line even though 
> I printed out 'name'!
> 
> But, it does look as though that path is supposed to form part of the 
> resulting filename.
> 
> -- 
> Bartc

Oh i see, so the code prompts for a name.. so i'm more lost than i thought, 
what do I need to change to make it just create the file with the chosen name 
Launch2.bat without the prompt?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Beginner] - Hanging in the code, can't figure out what's wrong

2016-04-03 Thread Loop.IO
On Sunday, April 3, 2016 at 1:12:23 AM UTC+1, BartC wrote:
> On 02/04/2016 23:31, Loop.IO wrote:
> 
> > Oh i see, so the code prompts for a name.. so i'm more lost than i thought, 
> > what do I need to change to make it just create the file with the chosen 
> > name Launch2.bat without the prompt?
> 
> If you don't want the user to enter anything, then I explained how 
> before, just use:
> 
>   name='C:\\Documents\\PythonCoding\\launch2.bat'
> 
> if that's the file name you need.
> 
> -- 
> Bartc

Hi Bartc, i tried that, didn't work
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Beginner] - Hanging in the code, can't figure out what's wrong

2016-04-03 Thread Loop.IO
On Sunday, April 3, 2016 at 1:08:59 AM UTC+1, Mark Lawrence wrote:
> On 02/04/2016 23:23, Loop.IO wrote:
> > On Saturday, April 2, 2016 at 11:09:13 PM UTC+1, BartC wrote:
> >> On 02/04/2016 22:59, Loop.IO wrote:
> >>> Hey
> >>>
> >>> So I built a keylogger using python as a test, got the code from the 
> >>> tutorial online, I want to improve on it to make it more automated, but 
> >>> the issue I'm having is it won't create the file until I press return, 
> >>> any clues where I'm going wrong?
> >>>
> >>> If I press return it makes the batch file, otherwise it just hangs.
> >>
> >>>   name=raw_input ('C:\\Documents\\PythonCoding\\')+'launch2.bat'
> >>
> >> You're asking for a file name to be entered. So that if ABC is pressed,
> >> followed by Enter, it will use:
> >>
> >> C:\Documents\PythonCoding\ABClaunch2.bat
> >>
> >> Assuming that's the intention, then Enter is needed so that it knows
> >> when the user has completed typing the name. If not, then just use:
> >>
> >> name='C:\\Documents\\PythonCoding\\launch2.bat'
> >>
> >> (If you want a single character name, without pressing Enter, that's
> >> harder to do. Someone else will have to help.)
> >>
> >> --
> >> Bartc
> >
> > Hey Bartc
> >
> > I don't quite understand what you mean?
> >
> > The file is just supposed to be created, I don't want to have to press 
> > "Enter" or "Return" for it to complete the file creation
> >
> > the info i followed to create the file advised I had to add the file name 
> > and extension on after like in the code
> >
> 
> There is no point asking BartC about Python as he has repeatedly stated 
> that he knows nothing about Python.  OTOH there are loads of people here 
> who do know Python, backwards, sideways and inside out.  If you state 
> precisely what you are trying to achieve then you will get the correct 
> answer.
> 
> -- 
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
> 
> Mark Lawrence

Hi Mark

Basically I want the program to do the search, which it does fine, then create 
the batch file then close.

What I will be doing once thats fixed is then adding a write to the batch file 
some lines of code, which im already testing and seems to work fine, its just 
the having to press enter to create the file and then close the program
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Beginner] - Hanging in the code, can't figure out what's wrong

2016-04-03 Thread Loop.IO
On Sunday, April 3, 2016 at 4:11:49 PM UTC+1, BartC wrote:
> On 03/04/2016 15:41, Loop.IO wrote:
> > On Sunday, April 3, 2016 at 1:12:23 AM UTC+1, BartC wrote:
> >> On 02/04/2016 23:31, Loop.IO wrote:
> >>
> >>> Oh i see, so the code prompts for a name.. so i'm more lost than i 
> >>> thought, what do I need to change to make it just create the file with 
> >>> the chosen name Launch2.bat without the prompt?
> >>
> >> If you don't want the user to enter anything, then I explained how
> >> before, just use:
> >>
> >>name='C:\\Documents\\PythonCoding\\launch2.bat'
> >>
> >> if that's the file name you need.
> >>
> >> --
> >> Bartc
> >
> > Hi Bartc, i tried that, didn't work
> 
> You mean it gave an error when you tried to create that file?
> 
> Does that path already exist on your machine? If not then trying to 
> create a file in a non-existent path won't work.
> 
> You can create the path manually outside of Python. Or look up the docs 
> to find out how to do that. A quick google suggested using os.makedirs 
> (to create multiple nested paths at the same time).
> 
> The following code worked on my machine:
> 
> import sys
> import os
> 
> def create():
>   print("creating new file")
> 
>   path="c:/Documents/PythonCoding/"
>   name=path+"launch2.bat"
> 
>   try:
>   os.stat(path)
>   except:
>   os.makedirs(path)
> 
>   print (name)
> 
>   try:
>   file=open(name,'w')
>   file.close()
>   except:
>   print("error occured")
>   sys.exit(0)
> 
> create()
> 
> -- 
> Bartc

The issue is that it hangs, there is no error. its like it pauses until i press 
enter, ill try what you've posted one moment
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Beginner] - Hanging in the code, can't figure out what's wrong

2016-04-03 Thread Loop.IO
On Sunday, April 3, 2016 at 8:32:06 PM UTC+1, Loop.IO wrote:
> On Sunday, April 3, 2016 at 4:11:49 PM UTC+1, BartC wrote:
> > On 03/04/2016 15:41, Loop.IO wrote:
> > > On Sunday, April 3, 2016 at 1:12:23 AM UTC+1, BartC wrote:
> > >> On 02/04/2016 23:31, Loop.IO wrote:
> > >>
> > >>> Oh i see, so the code prompts for a name.. so i'm more lost than i 
> > >>> thought, what do I need to change to make it just create the file with 
> > >>> the chosen name Launch2.bat without the prompt?
> > >>
> > >> If you don't want the user to enter anything, then I explained how
> > >> before, just use:
> > >>
> > >>name='C:\\Documents\\PythonCoding\\launch2.bat'
> > >>
> > >> if that's the file name you need.
> > >>
> > >> --
> > >> Bartc
> > >
> > > Hi Bartc, i tried that, didn't work
> > 
> > You mean it gave an error when you tried to create that file?
> > 
> > Does that path already exist on your machine? If not then trying to 
> > create a file in a non-existent path won't work.
> > 
> > You can create the path manually outside of Python. Or look up the docs 
> > to find out how to do that. A quick google suggested using os.makedirs 
> > (to create multiple nested paths at the same time).
> > 
> > The following code worked on my machine:
> > 
> > import sys
> > import os
> > 
> > def create():
> > print("creating new file")
> > 
> > path="c:/Documents/PythonCoding/"
> > name=path+"launch2.bat"
> > 
> > try:
> > os.stat(path)
> > except:
> > os.makedirs(path)
> > 
> > print (name)
> > 
> > try:
> > file=open(name,'w')
> > file.close()
> > except:
> > print("error occured")
> > sys.exit(0)
> > 
> > create()
> > 
> > -- 
> > Bartc
> 
> The issue is that it hangs, there is no error. its like it pauses until i 
> press enter, ill try what you've posted one moment

Ok the Bartc code gives me an error.

What is it that makes the code hang with what I have, you said it was that it's 
prompting for a name for the file, so how do I bypass that and force it to 
create the file with the name I've provided?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Beginner] - Hanging in the code, can't figure out what's wrong

2016-04-03 Thread Loop.IO
On Sunday, April 3, 2016 at 1:38:48 AM UTC+1, Mark Lawrence wrote:
> On 03/04/2016 01:12, BartC wrote:
> > On 02/04/2016 23:31, Loop.IO wrote:
> >
> >> Oh i see, so the code prompts for a name.. so i'm more lost than i
> >> thought, what do I need to change to make it just create the file with
> >> the chosen name Launch2.bat without the prompt?
> >
> > If you don't want the user to enter anything, then I explained how
> > before, just use:
> >
> >   name='C:\\Documents\\PythonCoding\\launch2.bat'
> >
> > if that's the file name you need.
> >
> 
> name = r'C:\Documents\PythonCoding\launch2.bat'
> 
> Alternatively you could just use a forward slash.
> 
> I'm not sure which is the most efficient, I'll leave that to others to test.
> 
> -- 
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
> 
> Mark Lawrence

Hey Mark,

Sorry i totally missed your input, and guess what, it solved it !!!

Thanks man, it created the file and finished, what is different with r and 
raw_input
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Beginner] - Hanging in the code, can't figure out what's wrong

2016-04-03 Thread Loop.IO
On Sunday, April 3, 2016 at 8:49:28 PM UTC+1, Erik wrote:
> Hi Loop.IO,
> 
> On 03/04/16 15:41, Loop.IO wrote:
> >> If you don't want the user to enter anything, then I explained how
> >> before, just use:
> >>
> >>name='C:\\Documents\\PythonCoding\\launch2.bat'
> >>
> >> if that's the file name you need.
> >>
> >> --
> >> Bartc
> >
> > Hi Bartc, i tried that, didn't work
> 
> FYI, for the future.
> 
> Telling someone what _didn't_ happen is generally not very useful to 
> them if you expect them to try to help further.
> 
> If you tell them what _did_ happen (be that an error message or a weird 
> file created or a pain in your leg or whatever), then that is much more 
> likely to be productive ;)
> 
> If you would like someone to diagnose your illness, you must explain 
> your symptoms ...
> 
> E.

The original post said what did happen, the code runs and hangs on the create 
file, and once i press Enter it then finishes and creates the file, not sure 
how you missed that but thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Beginner] - Hanging in the code, can't figure out what's wrong

2016-04-03 Thread Loop.IO
On Sunday, April 3, 2016 at 9:15:22 PM UTC+1, Erik wrote:
> On 03/04/16 20:54, Loop.IO wrote:
> > The original post said what did happen, the code runs and hangs on
> > the create file, and once i press Enter it then finishes and creates
> > the file, not sure how you missed that but thanks
> 
> Yes, I read your original post. That was days ago.
> 
> The comment I was replying to was you telling BartC that what he had
> suggested "didn't work" (with no further information).
> 
> Please pay attention to the context of the email you are responding to.
> 
> E.

Erik

It was a syntax error. But sure, thanks.

The problem has been rectified, I used the r as suggested by Mark.

I've now been able to get the file created and write the code in the file, 
thanks for everyones replies.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Beginner] - Hanging in the code, can't figure out what's wrong

2016-04-03 Thread Loop.IO
On Sunday, April 3, 2016 at 9:21:44 PM UTC+1, BartC wrote:
> On 03/04/2016 20:36, Loop.IO wrote:
> > On Sunday, April 3, 2016 at 8:32:06 PM UTC+1, Loop.IO wrote:
> 
> >> The issue is that it hangs, there is no error. its like it pauses until i 
> >> press enter, ill try what you've posted one momen
> 
> 
> > Ok the Bartc code gives me an error.
> 
> This is confusing! I know you said you fixed the problem now, but if it 
> was waiting for the user to press enter, then you still had a raw_input 
> or input() call in your code.
> 
> You need to get rid of that raw_input(). That was explained early on in 
> the thread but perhaps you didn't grasp that you had to use:
> 
>name = ''
> 
> in place of:
> 
>name = raw_input()
> 
> and not as well as!
> 
> (And the 'r' in name = r'' isn't a different version of raw_input(), 
> it's just a way of entering strings without having to type \\ when you 
> need \.)
> 
> -- 
> Bartc

Hey Bartc

I'm sorry about getting you confused, I did try that, but it didn't work, maybe 
it was me, but now I've tried it again it does work.

I've now managed to get the file to be created and write to the file so its all 
working fine.

The only question left is when I've conducted a search through all the drives 
for a browser .exe file, how do I take the search results and put them in to a 
text file, but I guess that's for another thread.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Beginner] - Hanging in the code, can't figure out what's wrong

2016-04-03 Thread Loop.IO
On Sunday, April 3, 2016 at 10:27:16 PM UTC+1, Erik wrote:
> Loop.IO:
> 
> On 03/04/16 21:25, Loop.IO wrote:
> > On Sunday, April 3, 2016 at 9:15:22 PM UTC+1, Erik wrote:
> >> On 03/04/16 20:54, Loop.IO wrote:
> >>> The original post said what did happen, the code runs and hangs on
> >>> the create file, and once i press Enter it then finishes and creates
> >>> the file, not sure how you missed that but thanks
> >>
> >> Yes, I read your original post. That was days ago.
> >>
> >> The comment I was replying to was you telling BartC that what he had
> >> suggested "didn't work" (with no further information).
> >>
> >> Please pay attention to the context of the email you are responding to.
> >>
> >> E.
> >
> > Erik
> >
> > It was a syntax error. But sure, thanks.
> 
> So, you reply to my advisory on how to report your problem by saying 
> that your original post said what did happen. Your original post said:
> 
> "the code runs and hangs on the create file, and once i press Enter it 
> then finishes and creates the file"
> 
> But it turns out that "It was a syntax error".
> 
> If it was a syntax error, them how did the code run and "hang on the 
> create file"?
> 
> Don't try to sweep my suggestion (that you should describe your symptoms 
> properly) under the carpet. It's a very important lesson to learn for 
> people trying to report bugs/issues.
> 
> E.

I think you've misunderstood chap

My initial issue didn't have a syntax error, it just hung in the code until I 
pressed Enter/Return.

I then tried Bartc's solution when I changed my code, which I then replied "it 
doesn't work", which as you pointed out was unhelpful.

You now seem to be on some sort of rampage as I've already recognised that it 
was short, and said I got a syntax error upon attempting the new code that 
Bartc provided. I then said thanks to you for pointing it out, if you want to 
call that sweeping it under the carpet, then so be it, but the issue was 
resolved.

That's really the end of the matter, whether you're fishing for some sort of 
recognition or brownie points I don't know, but try relaxing and taking a step 
back; the issue is resolved, I'm moving on with the program, I appreciate the 
replies from everyone (including you) so chill.
-- 
https://mail.python.org/mailman/listinfo/python-list