1

I am trying to run this file in MS visual studio 2015:

# This program says hello and asks for my name.
print('Hello friend!')
print('What is your name?') # ask for their name
myName = input()
print('It is good to meet you, ' + myName)
print('The length of your name is:')
print(len(myName))

I tried to run this in visual studio but after I input the "myName" field, the output window closes instantly. I tried to change the environment to Python3.4 and also IronPython, but the same result in both environments. I tried to run this file in Python3.4.2 Shell and there it works fine. Can you please troubleshoot this problem thanks

Rohail
  • 75
  • 1
  • 11
  • Try wrapping this all in a try/execpt block and print something in the except clause. It may give a hint. – tdelaney Nov 28 '15 at 04:22
  • didnt help,,any other suggestions please – Rohail Nov 28 '15 at 06:37
  • Those two asterisks at the end of the last line look a bit suspect. Also did you try putting another `input` call after the last line? – Paul Rooney Nov 28 '15 at 07:09
  • sorry by mistake I put the two ** at end of the code...thats why it seemed suspicious.i removed them now..the code works fine in python shell...yes I tried putting another input call at the end but same result..it wont work in visual studio – Rohail Nov 28 '15 at 08:56
  • In general, VS has the habit of closing the terminal after exit, discarding the whole output of the program including the important error messages. Consider running the program from the commandline or, in case of Python, giving the interpreter the `-i` flag to drop into interactive mode after that. – Ulrich Eckhardt Nov 28 '15 at 09:41

1 Answers1

0

Under the "Tools", "Options" dialog, find "Python Tools" and the "Debugging" page. On that page, you can configure whether the console closes automatically or waits for a keypress for both cases where it successfully completes and when it fails (based on the exit code).

By default, on successful completion, the console will close automatically. If an error terminates the program, it will prompt by default.

For IronPython projects, the default debugger is the .NET one, which does not respect these options. In "Project Properties", "Debug" you can switch to Standard Python Debugging, which generally is a better experience (though you can no longer step into C# code).

Zooba
  • 11,221
  • 3
  • 37
  • 40
  • I checked that page and according to configuration it should wait for input whether program completes normally or abnormally.I tried this simple program print ('whats ur age') myAge=input() print ("my age is "+ myAge) but it failed..I even tried to put input() in the end of the field..but still not working..I am using Iron Python environment...it should be noted that all program output windows close each time I write an input – Rohail Dec 05 '15 at 21:32
  • Updated to explain how IronPython is different – Zooba Feb 01 '16 at 16:07