Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

Program keeps closing unexpectedly...

Hey HF,

Well I am trying to make a basic repair tool using Python, it's being a real dick to me so I decided to ask for help...

Here's the current code...

PHP Code

<?php 
print("Hello and thanks for using Mike's Desktop AIO Repair Tool!")
raw_input("Press any key to continue...")
print(
"So what would you like to do?")
print(
"1) Scan HDD for errors & bad sectors.")
print(
"2) Fix registry errors.")
print(
"3) Scan for viruses and malware.")
raw_input("Press any key to continue...")

choice == raw_input("Please select an option...")
if 
choice == "1":
    
raw_input("Press any key to continue...")
    print(
"Now scanning HDD for errors!")
    print(
"Test...") 

What I want it to do is, after it says Now scanning HDD for errors! I want it to open command prompt, BUT I want the Python program to stay OPEN.

Can someone tell me how to make python open Command Prompt BUT keep python running as well?

I can't figure that part out :/

Cheers,
Mike
[img]http://www.wrestlingforum.com/signaturepics/sigpic205780_2.gif[/img]

(Jan 13, 2014 05:57 PM)W R T Wrote:  Hey HF,

Well I am trying to make a basic repair tool using Python, it's being a real dick to me so I decided to ask for help...

Here's the current code...

PHP Code

<?php 
print("Hello and thanks for using Mike's Desktop AIO Repair Tool!")
raw_input("Press any key to continue...")
print(
"So what would you like to do?")
print(
"1) Scan HDD for errors & bad sectors.")
print(
"2) Fix registry errors.")
print(
"3) Scan for viruses and malware.")
raw_input("Press any key to continue...")

choice == raw_input("Please select an option...")
if 
choice == "1":
    
raw_input("Press any key to continue...")
    print(
"Now scanning HDD for errors!")
    print(
"Test...") 

What I want it to do is, after it says Now scanning HDD for errors! I want it to open command prompt, BUT I want the Python program to stay OPEN.

Can someone tell me how to make python open Command Prompt BUT keep python running as well?

I can't figure that part out :/

Cheers,
Mike

Add raw_input() to the end of your script, and that will keep the console window open
(Jan 13, 2014 06:04 PM)Skyla Blue Wrote:  Add raw_input() to the end of your script, and that will keep the console window open

Still doesn't work, It just closes again.
[img]http://www.wrestlingforum.com/signaturepics/sigpic205780_2.gif[/img]

If you want to open a command prompt and keep your script open use subprocess.call . ( http://docs.python.org/3.3/library/subpr...ocess.call )
Using this, python will wait for the called program to exit before continuing.

Edit:
Example:
Code
import subprocess
subprocess.call("cmd.exe")
(Jan 13, 2014 06:48 PM)W R T Wrote:  Still doesn't work, It just closes again.

Try running it from command prompt, or terminal if you're on linux, and see if it gives you an error
It is actually very straightforward:
subprocess.call("A command")

"A command" can be anything you would input in a windows terminal.
Code
import subprocess

subprocess.call("notepad.exe")   #Starts notepad
subprocess.call("cmd.exe /c ipconfig")   #Start a command prompt and execute ipconfig
(Jan 13, 2014 07:32 PM)dberube Wrote:  It is actually very straightforward:
subprocess.call("A command")

"A command" can be anything you would input in a windows terminal.
Code
import subprocess

subprocess.call("notepad.exe")   #Starts notepad
subprocess.call("cmd.exe /c ipconfig")   #Start a command prompt and execute ipconfig

PHP Code

<?php 
print("Hello and thanks for using Mike's Desktop AIO Repair Tool!")
raw_input("Press any key to continue...")
print(
"So what would you like to do?")
print(
"1) Scan HDD for errors & bad sectors.")
print(
"2) Fix registry errors.")
print(
"3) Scan for viruses and malware.")
raw_input("Press any key to continue...")

choice == raw_input("Please select an option...")
if 
choice == "1":
    
import subprocess
subprocess
.call("cmd.exe") 

Current code, I appreciate your help! Now, when I get to where it says Press any key to continue... it just shuts the console down :l

Thanks a ton for the help by the way!

Cheers,
Mike
[img]http://www.wrestlingforum.com/signaturepics/sigpic205780_2.gif[/img]

1: Always put your imports at the beginning of you script. It's clearer.
2: I just noticed an error in you code:
Code
choice == raw_input("Please select an option...")
#Should be
choice = raw_input("Please select an option...")

Always remember:
"x == y" test if x is equal to y
"x = y" assign the value of y to x

3: For your error, try to run this code:
The only reason I see to stop working at raw_input is that you are using python 3.
Code
import subprocess

try:
    print("Just checking if you run python2...")
    raw_input
    print("Looks good to me!")
except:
    print("OOPS, seems you are running python 3.")
    print("Python 3 use input and not raw_input.")
    print("I'll fix this for you now. Next time use 'input'!\n\n")
    raw_input = input

print("Hello and thanks for using Mike's Desktop AIO Repair Tool!")
raw_input("Press any key to continue...")
print("So what would you like to do?")
print("1) Scan HDD for errors & bad sectors.")
print("2) Fix registry errors.")
print("3) Scan for viruses and malware.")
raw_input("Press any key to continue...")

choice = raw_input("Please select an option...")
if choice == "1":
    raw_input("Press any key to continue...")
    print("Now scanning HDD for errors!")
    print("Test...")
    subprocess.call("cmd.exe")
(Jan 13, 2014 07:53 PM)dberube Wrote:  1: Always put your imports at the beginning of you script. It's clearer.
2: I just noticed an error in you code:
Code
choice == raw_input("Please select an option...")
#Should be
choice = raw_input("Please select an option...")

Always remember:
"x == y" test if x is equal to y
"x = y" assign the value of y to x

3: For your error, try to run this code:
The only reason I see to stop working at raw_input is that you are using python 3.
Code
import subprocess

try:
    print("Just checking if you run python2...")
    raw_input
    print("Looks good to me!")
except:
    print("OOPS, seems you are running python 3.")
    print("Python 3 use input and not raw_input.")
    print("I'll fix this for you now. Next time use 'input'!\n\n")
    raw_input = input

print("Hello and thanks for using Mike's Desktop AIO Repair Tool!")
raw_input("Press any key to continue...")
print("So what would you like to do?")
print("1) Scan HDD for errors & bad sectors.")
print("2) Fix registry errors.")
print("3) Scan for viruses and malware.")
raw_input("Press any key to continue...")

choice = raw_input("Please select an option...")
if choice == "1":
    raw_input("Press any key to continue...")
    print("Now scanning HDD for errors!")
    print("Test...")
    subprocess.call("cmd.exe")

I really do appreciate the time, honestly, you helped me out a TON. Last question, would there be anyway that I can make Python run cmd as administrator? Or would I need to convert python to an .exe and make someone run it as admin?

Cheers,
Mike
[img]http://www.wrestlingforum.com/signaturepics/sigpic205780_2.gif[/img]

(Jan 13, 2014 08:00 PM)W R T Wrote:  I really do appreciate the time, honestly, you helped me out a TON. Last question, would there be anyway that I can make Python run cmd as administrator? Or would I need to convert python to an .exe and make someone run it as admin?

Cheers,
Mike

Converting the script to an .exe is an option but I think running the interpreter as admin would also work.

That is, maybe google know a way to elevate privilege from the command prompt?
Put this at the end of your code

Code
import os
os.system("pause")

or you can do

Code
import time
sleep(100) # this sleeps for 100 seconds


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by SwagDoggerMar 18, 2015 11:51 AM 4 117 Mar 18, 2015 11:51 AM
Last Post: Nuclear3mbargo
[C] by XerifApr 2, 2014 04:11 AM 9 309 Apr 2, 2014 04:11 AM
Last Post: Nichole
[.NET] by geraldososaJan 25, 2014 09:02 AM 4 119 Jan 25, 2014 09:02 AM
Last Post: geraldososa