Linux, Eclipse CDT run as su - c++

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.

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

Netbeans - run bash script before running the program?

might be a stupid question, but I've just started using Netbeans 10 for a C++ project.
When I run/debug the project, I'd need to first execute a bash script which sets up the environment, and then execute the binary (including an argument to be passed):
#!/bin/bash
source setup_script.sh
./bin/my_program -c some_argument
I've tried just pointing Project Properties -> Run -> Run Command to the .sh file containing this launch script, but that won't do it (the Run / Debug buttons are either greyed our, or it'll tell me it doesnt recognize the executable type).
Is there any way to setup Netbeans to launch my application via this script, or any other way to achieve the same - e.g. setting up some sort of pre-run command that'd execute setup_script.sh in the same session?
Thanks!

Scalatra will not run on Windows

I have been working on a Scalatra project on a Linux environment and would now like to switch to a Windows environment. I've transferred the project folder to my Windows directory. Using Cygwyn, I cd to the Scalatra project and type
./sbt
> jetty:start
Nothing happens at this point. I have waited 10 minutes but nothing is printed to the console. I am having a hard time thinking of what might be the cause, since the exact same project works fine on Linux. Anyone have a Scalatra project working on Windows and remember whether there were any Windows-specific steps to set it up?
I did this on a fresh Windows 10 Professional VM in virtual box. I only allocated 1 CPU and 4 GB RAM, which may have made things unnecessarily slow. I was logged in as administrative user testvm
I always started new command prompts after modifying environment variables. All of my command prompts were run as administrator... I don't know whether that was necessary.
In general, these instructions were a good start: How to Install conscript in Windows, followed by http://scalatra.org/getting-started/first-project.html
installed the java developers kit, by visiting this page
or here
added the JDK's bin folder (C:\Program Files\Java\jdk1.8.0_131\bin) to the end of the PATH system variable
started a new command prompt and ran set to review the PATH environment variable, and ran javac –version as an additional sanity check
downloaded and installed sbt for windows. Didn't make any manual changes to the PATH at this point.
conscript (or giter8?) requires bash (and/or git?), so I installed git for windows. I did a default install, except I specified that git and "optional Linux components" should all be accessible form the windows prompt. I also added C:\Program Files\Git\bin to the PATH environment variable. I’m not sure if either or both of those tweaks are required.
downloaded the latest conscript jar. I got a warning that the download might not be safe and accepted anyway.
double clicked the conscript jar to run it. A nice graphical dialogue box came up and eventually told me that a cs.bat script had been created in C:\Users\testvm\.conscript\bin\cs.bat. 100% CPU use continued for several minutes after this and eventually I clicked the close button (X) in the upper right of the conscript installer dialogue.
When I installed conscript in another system more recently, it went quickly but I got a warning that cs.bat might not be on the system path.
ran conscript to obtain giter8. I have found that giter8 v 0.8 fails to build the skeleton project with an error like "parameters cannot contain '.'", so I specifically asked for v 0.7.2: C:\Users\testvm\.conscript\bin\cs.bat foundweekends/giter8/0.7.2
ran giter8 to install the skeleton scalatra project: C:\Users\testvm\.conscript\bin\g8.bat scalatra/scalatra-sbt
accepted all of the default parameters
turned off the windows firewall, the defender real-time protection, and started a new cmd prompt as administrator. I don’t know if any of those are necessary
ran sbt: c:\Users\testvm\my-scalatra-web-app\sbt
Going through this more recently, my-scalatra-web-app was installed into c:\Windows\System32\my-scalatra-web-app, but I was able to copy it to the top of C:\. cd'ing in there and running just sbt gave an error message, because there's a sbt file in that folder, but it's not a windows executable. So I entered "c:\Program Files (x86)\sbt\bin\sbt.bat". Subsequently, that directory was added to my PATH environment variable, so I could just enter sbt.bat
waited as components downloaded, installed and compiled
when the sbt > prompt reappeared, entered jetty:start and waited some more
eventually, the following appeared:
2017-05-09 07:31:15.101:INFO:oejs.ServerConnector:main: Started ServerConnector#bffcb98{HTTP/1.1}{0.0.0.0:8080}
2017-05-09 07:31:15.101:INFO:oejs.Server:main: Started #8698ms
Opened http://localhost:8080 in a web browser and saw Hello, world!

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.

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.