How to run C program in Netbeans - c

I am trying to run the dmtx project from Git (link: https://github.com/dmtx/dmtx-utils) in Netbeans. I have configured the Project Properties in NetBeans and the project is building correctly.
When I run a particular C file (dmtxwrite.c) through bash it gives the correct output. As mentioned in the README, the correct way to run it in Bash is:
$ echo -n 123456 | dmtxwrite > image.png.
Now my question is how can I do the same using NetBeans?
Till now I only found answers related to passing command line arguments. However, that does not work.

how can I do the same using NetBeans?
Select your C project in the Projects panel.
Right-click it to open the context menu, then select Properties > Run > Run Command.
Enter your command to be run in the Run Command field.
This is the Help for Run Command in NetBeans 8.2:
Enter a command to be executed when you run the project. The IDE runs the command as /bin/sh -c "run-command" which enables you to use any shell syntax including redirection and pipes. Type the command in the Run Command field the same way you would run it from the command line. For example, you could type my-script -opt1 -opt2 to run a script and specify two options, or mycommand > output.log to run your command and send the output to a logfile. The Run Command list maintains history of previous entries so you can go back to the default value or select among several different commands you have entered.

Related

Creating mongoDB alias with .bash_profile on the cmder is not working

this is my first ever question. Okay..
Relevant to this problem :
I am using cmder
I am new to the terminal
I am using a windows PC
I'm following a tutorial on how to install mongoDB locally, after running the setup my first problem came when
On the terminal The tutor did
Cd ~
To go to the home directory but when I tried the same command on the cmder I received
The system cannot find the path specified
So I navigated manually using "cd.. " to
c:\Users\<username>
Which I think is the home directory,I created the ".bash_profile" file and saved the following commands in it
alias mongod = "/c/program\ files/MongoDB/server/4.4/bin/mongod.exe"
alias mongo = "/c/program\ files/MongoDB/server/4.4/bin/mongo.exe"
But when I run the mongod or test if it's installed completely it returns
'mongod' is not recognized as an internal or external command, operable program or batch file
Please I don't know my way round the terminal that much, please be detailed with answers
Thanks in advance
alias mongod="/c/Program\ Files/MongoDB/server/4.4/bin/mongod.exe"
alias mongo="/c/Program\ Files/MongoDB/server/4.4/bin/mongo.exe"
Removing spaces and making uppercase the first letters of program files worked for me.
cmder doesn't interpret shell arguments like ~, which means tilde won't work in paths. Also, be aware the way you spelled Cd. It can cause an error in other command line tools (case sensitive ones like Git Bash).
1 - If you're using cmder/cmd.
Use doskey to create an alias/shortcut:
Create C:\bat\macros.txt to store your macros/aliases and paste:
cdhome=cd /d %HOMEDRIVE%%HOMEPATH%
mongo="C:\Program Files\MongoDB\Server\4.4\bin\mongo.exe" $*
mongod="C:\Program Files\MongoDB\Server\4.4\bin\mongod.exe" $*
Rename everything you want but %HOMEDRIVE%%HOMEPATH%. $* at the end means the command accepts arguments, like mongo --version.
Keep in mind that .bash_profile isn't related with cmder/cmd, that's why your mongo commands are there too.
Then Windows + R and type regedit.
Go to HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\
Right-click and add a new "String Value". Name it Autorun.
Right-click it and modify the value data to DOSKEY /MACROFILE="C:\bat\macros.txt"
2 - If you're using Git Bash, Hyper terminal, etc.
On .bash_profile, just remove the spaces around the equals sign. Like:
alias mongod="/c/program\ files/MongoDB/server/4.4/bin/mongod.exe"
alias mongo="/c/program\ files/MongoDB/server/4.4/bin/mongo.exe"
or on Windows, you can just go to System properties/Advanced/Environment Variables. Under System variables, find the Variable called Path. Click edit, then New and paste in the path of the mongoDB bin folder:
C:\Program Files\MongoDB\Server\4.4\bin
keep in mind to write version your mongodb correctly in path, now its 4.4
By adding a path to the path variable you can access the .exe files from that path no matter where you are in the directory. It serves the same purpose as the .bash_profile file. Doing it this way allows this to work with windows cmd prompt or cmder as well. Upon launching, the bash emulator gets the environment variables from Windows anyways.
After adding the mongoDB path, open cmd prompt or any bash emulator and type in mongo. It will load up mongo.exe regardless of your current working directory.
Be Specific about the spaces after alias.
alias alias_name ="path.."
I faced alot of issues despite so many answers so this worked for me.
1.First install git and hyper terminal
2.Click the '~' sign to enter the home directory and then make a new file ".bash_profile"
Enter the command "vim .bash_profile"
Now enter 'i' key to enter the insert mode
Copy paste the exact command below:
alias mongod="C:/Program\ Files/MongoDB/Server/5.0/bin/mongod.exe"
alias mongo="C:/Program\ Files/MongoDB/Server/5.0/bin/mongo.exe"
(make sure that you use forward slash '/' for path and "\" backward slash to indicate space between program and files)
enter esc
write the command ':wq!' and click enter
restart hyper terminal and check the installation by running the command 'mongo --version'
Use git bash instead of CMDER
OR
Try to install mongosh from this link:
[1]: https://www.mongodb.com/try/download/shell?jmp=docs
And after setup go to hyper terminal and write mongosh => to connect to MongoDB on port 27017 and then you will see => test>
now you are ready to use the Database and you can write help to see Shell Help.
Check if mongo.exe or mongod.exe files are exist. In my case the bin directory had mongos.exe instead of mongo.exe.

I'm new to command line. I get a lot of messages like 'command not found' and 'no such file or directory'

Trying to run gcloud init to initialize the Google App Engine Engine SDK by typing ./google-cloud-sdk/bin/gcloud init but it showed: no such file or directory or command not found. Is something wrong with my PATH? My path is:
/Users/AnneLutz/Documents/google-cloud-sdk\
If you typing ./google-cloud-sdk/bin/gcloud init and you installed Cloud SDK in /Users/AnneLutz/Documents/google-cloud-sdk, then your current directory should be /Users/AnneLutz/Documents in order for what you type to work.
That said you should add /Users/AnneLutz/Documents/google-cloud-sdk/bin to you path. To do this, assuming you are using bash you can
source /Users/AnneLutz/Documents/google-cloud-sdk/path.bash.inc
To make it so that every-time you start your shell you can add it to shell profile. For example you can add above source command at the end of ~/.bash_profile file.
It looks like you used the option to download the SDK zip file and are then trying to configure your environment with that download option. If you aren't comfortable with setting environment variables, you might want to instead try installing using the "interactive" installer, which will automate the steps for making the commands always available on your system.
The directions are here, but for Mac OS users are basically:
Enter the following at a command prompt:
curl https://sdk.cloud.google.com | bash
Restart your shell:
exec -l $SHELL
Run gcloud init to initialize the gcloud environment:
gcloud init
For many, this procedure is easier than getting everything configured manually.

Automating putty with .bat file [duplicate]

I want to run a few shell commands every time I SSH to a server via PuTTY. I'm connecting to a production web server managed by someone else, and I don't want to store my own scripts there.
I see the option Connection > SSH > Remote Command, but if I put my initialization commands there, after starting the session, it closes immediately after the commands execute. How can I run the Remote Command, and then keep the session open so I can continue using it?
The SSH session closes (and PuTTY with it) as soon as the command finishes. By default the "command" is a shell. As you have overridden this default "command" and yet you want to run the shell nevertheless, you have to explicitly execute the shell yourself:
my-command ; /bin/bash
See also Executing a specific command on the server.
One option to go is set up your putty remote command like this:
ls > dir.ls & /bin/bash
In this example command you want to run is "ls > dir.ls" what creates file dir.ls with content of directory listing.
And as you want to leave shell open you can add aditional command "/bin/bash" or any other shell of your choice.

Editing .desktop file to run executable as root?

I have compiled a c program into an executable that I would now like to integrate into the applications menu in Debian 7.4 XFCE. In order to run the application under normal circumstances, I am required to type
sudo myprogram
Now I have created my .desktop file and placed it in /usr/share/applications
[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=myprogram
Comment=configuration loader
Exec=sudo loader
Icon=/usr/share/icons/hicolor/48x48/apps/myprogram.png
Terminal=false
Categories=Development;IDE
The item is added to my applications menu as expected, and the icon shows up properly. The problem, however, is that double clicking the menu item to launch the application does nothing.
If I navigate to /usr/bin (where I have placed my executable) and type "sudo myprogram", the program launches as expected.
What can I do to fix this issue and get the program to launch from the menu? Perhaps /usr/bin is not the correct place to put it, or I have the incorrect Exec command. I greatly appreciate the help.
I ended up using (after installing gksu)
Exec = gksu myprogram
this launches a graphical sudo prompt, which is sufficient for my needs.
This is what the setuid bit in the permissions is for. It makes executables run with permissions of the file owner. This only works on actual executables, not on shell scripts!
sudo chmod u+s myprogram
sudo chown root myprogram
./myprogram # now runs as root
Please be careful when using this as it will always execute that program as root no matter who executes it. You can limit access by setting it to your usergroup and deny all execute.
chgrp "${USER}" myprogram # provided you have individual groups set up
chmod a-x myprogram # deny all execute
This approach does not need additional installation of packages.
Terminal=true opens a new terminal window which runs
sudo -i to ask for the password.
Then, using sh to run the program, the Terminal is closed and myprogram runs in the background because it has a & at the end.
[Desktop Entry]
Type=Application
Name=...
Exec=sudo -i sh -c "myprogram &"
Terminal=true
Request: Please report if it works under your OS.
Tested under:
Xubuntu
The pkexec solution from askubuntu:
Exec=pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY APP_COMMAND
Try adding this to .desktop
Path=/path/to/myprogram

Logging into Cygwin and executing commands using bat file in windows

I am using windows XP operating system and cygwin is installed in my C drive.
I need to login to cygwin directly to my directory path which contains a makefile and also a bash script called build.sh in the same directory. So i modified the original cygwin.bat file and added the line as shown below.
#echo off
C:
chdir C:\cygwin\bin
bash --login "/cygdrive/E/scheme_31july/build/build.sh"
When i double click on this bat file i could see my script executing but not on cygwin shell but on windows cmd shell as a result I get errors for "make" command like "No rule to make target" as make comes bundled with cygwin.
And when I explicitly login to cygwin using default cygwin.bat file and execute my script by giving following commands in cygwin shell the script executes without errors.
Basically I want to write a bat file so that I can keep it anywhere in my PC and instead of manually openeing the cygwin prompt and typing commands like:
$ cd /cygdrive/E/scheme_31july/build/
$ sh build.sh
it should happen automatically. I sit possible to do so.
Regards,
Harshit
No rule to make target sounds more like make being executed in the wrong directory. make itself seems to be available and running as intended.
Try this:
bash --login -c "cd /cygdrive/E/scheme_31july/build/ && sh build.sh"
This should start a --login session (which should give you access to all the settings and tools you'd expect in a cygwin prompt environment), then execute the given shell command, which is the cd and sh you asked for. You could also write those two lines to a separate script file, and pass the name of that to bash instead of the full path to build.sh.
You could also try to cd into C:\scheme_31july\build in the bat file and then execute bash from there. Not sure whether bash will try to change path upon entering the login session. You can try whether things work without the --login, both for this approach and the one above.
#echo off
C:
cd C:\scheme_31july\build
C:\cygwin\bin\bash.exe ./build.sh
I'm not sure whether you want the session to turn interactive after that or not. In the above case, bash will terminate after the script completed, and might even close the window. You might have to add a read into build.sh to avoid that. If you want bash to turn interactive after executing some command, you can try using the --rcfile option of bash to execute some commands and then turn interactive.

Resources