4

I have the following code in my batch file

@ECHO OFF
SET /P NAME=Enter name:
SET /P GENDER = Enter age:
SET /P AGE = Enter gender:
python test.py %NAME% %GENDER% %AGE%
PAUSE

Here is the code in test.py

import sys

print len(sys.argv)

for arg in sys.argv:
    print arg

Here is the output

Enter name:Dodo
Enter age:1
Enter DB gender:M
2
test.py
Dodo
Press any key to continue . . .

I am using python2.5. How do i pass the age and gender as well? I'm new to both python and batch programming, so go easy on me :)

2
  • 3
    Why don't you just put the whole program in Python? Have it prompt for input. Commented Jun 27, 2012 at 6:36
  • thanks :) will try that out, but can it be done this way? Commented Jun 27, 2012 at 6:43

2 Answers 2

5

You must not use spaces around the = in set:

SET /P NAME=Enter name:
SET /P GENDER=Enter age:
SET /P AGE=Enter gender:

Otherwise you get a variable that ends with a space and you'd have to use it like %GENDER %.

Sign up to request clarification or add additional context in comments.

Comments

1

try enclosing in quotes. you also have a space by the equal signs, not sure if thats a problem with batch...

spaces:

SET /P GENDER = Enter age:
SET /P AGE = Enter gender:

and none for:

SET /P NAME=Enter name:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.