Run python script in interactive mode - python-2.7

With a previous install of Python 2.7 on a Windows 7 machine I could start a script by right-clicking on the filename in windows explorer. Ther was a menu option "Run in interactive mode". By clicking that, a screen would open up, the script would run and.... it would stay open to inspect the output on the screen and do some further actions.
In a fresh install on a Windows 8 machine, this menu option is not present. I can dubble click or Open the file, but then the window closes after running the script.
How can I create the menu entry "Run in interactive mode" when right-clicking on a py file in Windows 8?
I could not find answers in this site or on the Python site.

What you need to do is to add "-i" option when run a python file.
C:\windows\system32>python -i main.py
Then you will go into the interactive mode, where you can print current variables, call functions and so on.
To make it as a right menu, you can add following cotent to Windows Registery.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Python.File\shell\Run in interactive mode]
[HKEY_CLASSES_ROOT\Python.File\shell\Run in interactive mode\command]
#="\"C:\\Python27\\python.exe\" \"-i\" \"%1\" %*"

Related

How do I open WebStorm from terminal?

I've looked around but I've only found answers for past versions. I have a new version of WebStorm and I want to open my projects from the command line, but wstorm . and webstorm . doesn't seem to work.
I've tried going to Tools > Create Command Line Launcher... and I get this:
I go to ToolBox's WebStorm Settings and I'm met with this:
Generate shell scripts is turned on, but the but the commands still do not work in my terminal.
Am I missing something? Am I supposed to add in a Shell scripts location? I'm not entirely sure I understand.
It's actually very easy. First you open up Webstorm, and press SHIFT twice. This will bring up a search box, where you type: Create Command Line Launcher. You will see a search result from Tools will be highlighted, click on it, and it will suggest the default path. Just click on Ok. Your command line launcher is now ready, so you can open terminal, cd to your project root folder, and type webstorm ./ to launch webstorm.
If the Create Command Line Launcher option is not working, try the following:
If you are on MacOS, try adding the path as instructed in their official page. And if you are on Linux, just uninstall the current version and reinstall as a snap package using sudo snap install webstorm --classic. This way, you can launch it from the terminal just by typing webstorm
After opening a ticket with Jetbrains support, the default path is /usr/local/bin. Adding this worked.
You can use open-ide tool. It allows you to define all of your editors and to open any folder with your editor straight from terminal

How to execute a CLion program in gnome terminal?

This question already has an answer here but I am using CLion version 1.2.1 and the answer in that post doesn't help. It is possible to run a CLion program in gnome terminal instead of its own console ? If yes, how ? Thanks.
EDIT : I know where the executable file are stored but want to know if it is possible to run the file in terminal directly from the ide i.e. by selecting the run option in ide.
Yes, you can execute a Clion c/c++ program in a gnome terminal from the IDE. Here is how:
In the top right of your clion application you should see your project name or "Build All". Click on that and go to "edit configurations"
there click on the plus sign(top left) and then on "Application"
Now go to "Executable:" and click on "select others". There you should go to where your gnome-terminal is stored (mine is at "/usr/bin/gnome-terminal" on ubuntu)
Next go to "Program arguments:" and type -e ./myProjectName (For newer versions of gnome-terminal -e is deprecated, use -- ./myProjectName)
go to "Working Directory:" and type in the location to your cmake-build-debug folder found in your project folder
You can now press okay and go to the top right to select the name of your application that you created in step 2
This will run your program in the gnome terminal.
Hope this helped :)

Run as administrator not showing in start menu

Background:
My C++ application developed by VS2008 and use the VS setup project to create installer for that. After installation it will create two shortcuts to application. one is in user desktop and second one is in start menu. Application(myApp.exe) installed to the Program files directory.
Question: If I right click on the icons in the start menu, there is a option Run as Administrator for most of them. But if I right click on the shortcut that related to my application. It doesn't show Run as Administrator. How to fix this?
Edit: But if i right click on the myApp.exe in the Program files, it shows "Run as Administrator".
Set your embedded manifest to require administrator. On the project property page:
...on the (highlighted) UAC Execution Level, change asInvoker to requireAdministrator. Build your project to embed the new manifest, and it should be ready to do its thing.
Oh -- I didn't think to do it here, but in the Configuration drop-down, you probably want to select All Configurations, instead of the (default) Active configuration that's selected in the screen shot. Gets seriously annoying -- you think you've got things fixed, then you change to "Release" and a bunch of stuff suddenly breaks, and you have to go through figuring out what you'd changed, and edit those changes into the Release configuration as well.
In manifest file there is option "requestedExecutionLevel" and "UIAccess" which will manage it.
I found the answer for this after so much testing and searching. So here I mention it for use of any one.
Windows only shows Run as Administrator in the context menu for that shortcuts those are directly targeting to some exe file.
If you use VS deployment (setup) project to create your installation with desktop and start menu shortcuts. Those shortcuts not targeting to exe (Application.exe) file.
Instead of that shortcuts targeting to application folder (MS office 2007 also same). This is called installation-on-demand and advertisement. Here is the more details.
This will help your application to repair from file missing (pray Google for more).
So we have to disable this feature if you want to target your shortcuts directly to exe file.
For this you can use command prompt or some tool. here is how to do it.
Nirmally windows installer having a exe and a msi.
These setting are stored at at msi generated with setup file.
So You have to alter the file and add the entry DISABLEADVTSHORTCUTS=1 to property table.
Using Command prompt:
msiexec /i <path to your msi> DISABLEADVTSHORTCUTS=1
Using Orca Tool:(Meny other tools also there)
Download Orca tool from here and install it.
Right click your *.msi file and click edit with orca.
Go to property table and add new entry DISABLEADVTSHORTCUTS and value is 1 , save and close.
Now you done.
Install using setup.exe file and check the target of the shortcuts. those are directly target to the exe file in application folder.
Now if you right click on the shortcuts those shows Run as Administrator option in context menu.
Note: Doing this you will gain Run as Administrator but scarify the windows auto repair capability.

Linux, Eclipse CDT run as su

I am using Eclipse CDT to write an application. The application uses a third part API, which requires to run as sudo, in order to open raw sockets, etc.
In command line, I can run the program something like
su
./program
But in Eclipse CDT environment, it won't work if I press Ctrl + F11 (Run->Run Last Launched), I guess the reason is that my Linux GUI login is not su.
Is there anyway that I can run as su (with su password) in Eclipse CDT?
Thanks.
Some of the options you have:
Run Eclipse as root. (Not a very good idea, imho, but the simplest one)
Temporarily enable your user to use that library. (Could be messy)
Create a new run configuration and make a script to run your executable.(You've to enter the password everytime).
(#Others, feel free to add more.)
You can create a run configuration in which you use sudo to run your application. Since sudo doesn't have access to a terminal if you launch it this way, it requires setting the SUDO_ASKPASS environment variable in your launch configuration. The steps are as follows:
Creating a new Run configuration (for the sake of completeness):
In eclipse, right click your executable (i.e. the result of the build of your application) to open the context menu
In the context menu, go to Run as -> Run configurations ...
In the Run configurations window that appears, right click C/C++ Application and click New.
Modifying the Run configuration
In the Run configuration's Main tab, replace the C/C++ Application field by
/usr/bin/sudo.
Go to the Arguments tab, and enter the path to your executable, e.g. ./bin/my-executable. Note: sudo's working directory is the eclipse project, so the path should be relative to that.
If your executable requires any commandline arguments, add those, e.g. ./bin/my-executable arg1 arg2
Adding a way for sudo to ask for your password.
This is the most tricky part. Since sudo does not have a terminal (tty) at its disposal when run from the (eclipse) gui, we need to provide it with a program that can obtain the password for it, i.e. an askpass program. For more info, see this stackoverflow answer.
On my system (Ubuntu 15.04), the package ssh-askpass-gnome provides an askpass program, as I found out by running dpkg --get-selections | grep askpass. Since that still didn't give me the executable name, I brute-forced the search by running
sudo find -name *askpass*. Anyway, if no such utility is installed, search for it using your favourite package manager.
Once we've installed and / or located an askpass program, we can continue creating our launch configuration in eclipse; continue from step 2.3
In the Run configuration window, select the Environment tab and click new.
In the dialog that pops up, enter SUDO_ASKPASS as name and the full path to the askpass program as value, e.g. /usr/bin/ssh-askpass.
Press Apply to save our changes.
Executing the launch configuration
In the Run configurations window, press Run to launch our executable using the newly created launch configuration.
A pop-up window for entering the sudo password will appear.
After succesful password entry, our executable will run with root priviliges.

Django django-admin.py command problem

I'm new to Python and Django. In fact, I'm new to web framework too. I'm using Windows 7 OS and have installed Django.
I knew Django has been installed successfully. When I go to tutorials, this command, "django-admin.py startproject appproject" always suggested to be run before starting the project.
However, when I run this command, django-admin.py was not recognized as keyword.
Can anyone please help me to see what's wrong here?
On windows python scripts get installed to C:\Python27\Scripts (by default for Python2.7). However the python installer does not automatically Add this location to your PATH. What you need to do is either replace any call to django-admin.py with C:\Python27\Scripts\django-admin.py, or add it to your path. You can do that by:
Open your Start Menu and Locate My Computer, Right Click on it and choose Properties
On the left hand side select "Advanced System Settings".
Next click on the "Environment Variables" button.
Look in the bottom scroll box until you find one named PATH. Select this and hit Edit.
To the end of the current value, append ";C\Python27\Scripts".
Close/Save everything, including your cmd.exe prompt. When you reopen it C:\Python27\Scripts should be on your path, and django-admin.py should work.