2 Replies - 1225 Views - Last Post: 16 May 2013 - 05:09 AM Rate Topic: -----

#1 wchristner   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 15-May 13

edit a .cmd file using a list menu and if statements.

Posted 15 May 2013 - 08:18 PM

I am working on a project. I want to edit a .cmd file named Autorun_Ghost.cmd. this file only has one line of text.
i am using if statements and opening the file for write. I have the program running without errors but the .cmd file dose not change. I have tested this with a test.txt file i created but nothing is eddited there either. If someone could give me some direction i would be very greatfull. I thought If statements would be the easiest way of doing this. Thanks for the help. My code is as follow.

print                 "Choose an Image"
print "1)Ubuntu"
print "2)Windows Embedded Standard 2009 XP"
print "3)Windows Embedded Standard 7"
print "4)Windows POSReady Embedded Standard 2009"
print "5)Windows XP Tablet Edition"
print "6)Windows 7 Pro"
print "7)Windows 7 Ultimate"

fo=open("Autorun_Ghost.cmd", "w+")

raw_input("Choose OS 1-7  ")
if input == 1: fo.write ("\\programs\\ghost11\\ghost32.exe -clone,mode=restore,src=x:\\88ubun1.GHO,dst=1 -IR -SURE")
if input == 2: fo.write ("\\programs\\ghost11\\ghost32.exe -clone,mode=restore,src=x:\\88WES.GHO,dst=1 -IR -SURE")
if input == 3: fo.write ("\\programs\\ghost11\\ghost32.exe -clone,mode=restore,src=x:\\88wes7.GHO,dst=1 -IR -SURE")
if input == 4: fo.write ("\\programs\\ghost11\\ghost32.exe -clone,mode=restore,src=x:\\88POSR.GHO,dst=1 -IR -SURE")
if input == 5: fo.write ("\\programs\\ghost11\\ghost32.exe -clone,mode=restore,src=x:\\88xpTab.GHO,dst=1 -IR -SURE")
if input == 6: fo.write ("\\programs\\ghost11\\ghost32.exe -clone,mode=restore,src=x:\\88win7.GHO,dst=1 -IR -SURE")
if input == 7: fo.write ("\\programs\\ghost11\\ghost32.exe -clone,mode=restore,src=x:\\88w7ult.GHO,dst=1 -IR -SURE")


Is This A Good Question/Topic? 0
  • +

Replies To: edit a .cmd file using a list menu and if statements.

#2 Mekire   User is offline

  • D.I.C Head

Reputation: 118
  • View blog
  • Posts: 216
  • Joined: 11-January 13

Re: edit a .cmd file using a list menu and if statements.

Posted 15 May 2013 - 11:02 PM

Well your program doesn't work because raw_input returns a string and you never converted it to a number.

Edit: Actually you never even stored the raw_input in a variable...

But why do you want "w+" mode. I do believe you want plain "w" mode.



Edit2: Slight change.

This post has been edited by Mekire: 15 May 2013 - 11:16 PM

Was This Post Helpful? 0
  • +
  • -

#3 baavgai   User is offline

  • Dreaming Coder
  • member icon

Reputation: 7181
  • View blog
  • Posts: 14,969
  • Joined: 16-October 07

Re: edit a .cmd file using a list menu and if statements.

Posted 16 May 2013 - 05:09 AM

If you have items in a list, use a list.

Just for play:
available = [
	("Windows Embedded Standard 2009 XP","WES"),
	("Windows Embedded Standard 7","wes7"),
	("Windows POSReady Embedded Standard 2009","POSR"),
	("Windows XP Tablet Edition","xpTab"),
	("Windows 7 Pro","win7"),
	("Windows 7 Ultimate","w7ult"),

print "Choose an Image"
print "=================================================================="
print "\n".join("{0}) {1}".format((i+1),n) for i,(n,t) in enumerate(available))
print "=================================================================="

input = raw_input("Choose OS 1-{0}  ".format(len(available)))
found = [ (n,t) for i,(n,t) in enumerate(available) if str(i+1)==input ]
if found==[]:
	print "None chosen"
	(n,t) = found[0]
	print "Writing", n
	with open("Autorun_Ghost.cmd", "w+") as fo:
		fo.write ("\\programs\\ghost11\\ghost32.exe -clone,mode=restore,src=x:\\88{0}.GHO,dst=1 -IR -SURE".format(t))

This had the advantage that you can add to and remove from the list of items without having to make changes anywhere else. It does use some serious python silliness, but that's fun too.

Note, we don't need to close, because the with open will do that for you. Also, we don't write a file unless they choose a correct answer.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1