Permission denied in Linux [closed] - c++

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I have logged as root on Linux machine. Now trying to execute a binary file test of C++ but it produce an error "Permission denied". While I have given the permission to the binary (test) using chmod +x test.
Thanks

If the file test is located on a separate mount point, and that mount point is mounted with the noexec flag, you will not be able to execute any binaries on it.
From the mount manpages:
noexec Do not allow direct execution of any binaries on the mounted filesystem.
You can see what flags mount points are mounted with using the following command:
mount -l

If the binary test resides in the directory /dir1/dir2, do either of this (using absolute path):
/dir1/dir2/test
or navigate into the directory containing the program and use the ./ prefix (aka relative path)
cd /dir1/dir2
./test

Try the command ls -l /path/to/your/file after chmod +x /path/to/your/file.
After that, check if the executable bits x are present, i.e., look to the first string that will be printed, it should be something similar to -rwxrwxr-x.
If you don't have the three x, you have a problem with chmod. Probably you're not root.
If you have the x but can't execute the program, the problem is
with your call to the program. You should try to cd into the folder
where the program is located and then execute it like
./program_name.

There's a command called "test" that might be in your path before your code is, which is why you'd type "./test" instead of just "test", which will be found in /usr/bin/test, probably. ("which test" to find out on your system)
I don't know why /usr/bin/test would fail with that error, unless your test software takes parameters and you were giving the (on my system) /usr/bin/test a command that it couldn't do.
If it's not called test, and it's not a path issue, could you post some code and build details?

Related

BCP command in shell script fails when called from C [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 days ago.
Improve this question
I have a simple bcp command as mentioned below.It works when I execute it from a shell script or as a command on a RHEL server.
/opt/mssql-tools/bin/bcp *schema_name.table_name* format nul -n -q -f */tmp/format_file* -U *username *-P *password *-D -S *Synp*
This command is to produce a format file for a SQL table existing on Azure synapse.
When I execute directly on terminal it works fine.
when i put in bash script and execute bash on terminal works fine(sample below).
#!/bin/bash
/opt/mssql-tools/bin/bcp *schema_name.table_name* format nul -n -q -f */tmp/format_file* -U *username *-P *password *-D -S *Synp*
But when the shell script is called/executed from a C++ program using an exec command it gives the below error-
The table name specified exceeds the maximum allowed length.
Its called remotely.
It looks like it has trouble recognising the parameters but I really can't understand the reason why.
To make matters worse when I tried executing a bcp out or in command it works just fine.It looks like it is only bcp format that has this issue regarding parameter interpretation.
Any help is apprceiated
I tried checkin environment variables but couldnt find anything.

error while Linking c++ and ns2? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
had done following steps
Download "ex-linkage.cc" file, and save it under the "ns-2" directory.
Open "Makefile", add "ex-linkage.o" at the end of object file list.
Re-compile NS using the "make" command. Download the "ex-linkage.tcl" file
that contains "MyAgent" testing OTcl commands.
Run the OTcl script using command "ns ex-linkage.tcl".
i am getting following error
$ ./ns ex-linkage.tcl
invalid command name "Agent/MyAgentOtcl"
while executing
"Agent/MyAgentOtcl create o3 "
invoked from within
"catch "$className create $o $args" msg"
invoked from within
"if [catch "$className create $o $args" msg] {
if [string match "__FAILED_SHADOW_OBJECT" $msg] {
delete $o
return ""
}
global errorInfo
error "class $..."
(procedure "new" line 3)
invoked from within
"new Agent/MyAgentOtcl"
invoked from within
"set myagent [new Agent/MyAgentOtcl]"
(file "ex-linkage.tcl" line 8
»» invalid command name "Agent/MyAgentOtcl" «« : Looks like you are using an executable 'ns' with no "Linkage".
tar xvf ns-allinone-2.35_gcc482.tar.gz
https://drive.google.com/file/d/0B7S255p3kFXNSGJCZ2YzUGJDVk0/view?usp=sharing
cd ns-allinone-2.35/
patch -p0 < linkage_ns235.patch
https://drive.google.com/file/d/0B7S255p3kFXNYmZ0SWFQaUNhWTA/view?usp=sharing
./install
cd ns-2.35/
sudo make install
cp ns ns235-linkage
sudo cp ns235-linkage /usr/local/bin/
Simulation : ns235-linkage ex-linkage.tcl
.
warning: no class variable Agent/MyAgentOtcl::my_var2_otcl
.
Message From MyPrivFunc
my_var1 = 2
my_var2 = 3.140000
Using the "ns235-linkage" command makes sure you are using the right 'ns'.
P.S. : You are not recompiling with 'make', but with 'make clean && make'. Or by running './install' in the top directory ns-allinone-2.35/.
ns2linkage-ns2
OK, Cygwin. ( Why hide important information http://www.catb.org/~esr/faqs/smart-questions.html ).
The patch command : Install 'patch' , or install the 'Developer tools' if available.
You can use the {ns-2.35/} that comes with ns-allinone-2.35_gcc482.tar.gz ,,, and use the otherwise Cygwin installed {tcl8, tk8, otcl, tclcl}.
Besides that, the patch is just containing the two files ex-linkage.*, and a line for Makefile.in . The patch is supposed to make things easier.
Using : Make a copy of "linkage_ns235.patch" in the folder where you keep ns-2.35/, and do $ patch -p0 < linkage_ns235.patch
cygwin
OK, no working patch function in your cygwin, it seems.
May be your previously setup was OK, and you just have to recompile :
$ cd ns-2.35/ && make clean && make

Running a c++ file from command line [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm very much used to Visual Studio, but a HW assignment requires that the finished product be run from the command line. I've built it in Visual Studio to make sure my code is at least syntactically correct and won't cause any compiler to throw me a message, but he designed the template so that it would only really work on Command Line. Therefore, I need the command line to test the functionality of the code
TL/DR: the jist of it is: I should be able to run it from command line by typing in:
programName argument
How do I do this with a .cpp?
It should be
Programname.exe argument 1 argument2 ... argumentn
Make sure you're running the program in the correct path or specify the full path of the .exe
First open command prompt than type cd and your file's location ( Bot don't write your program's name.Example we have a test.exe in our desktop. If we open the command prompt we will see something like this: C:\Users\Username\ : We should locate the file so we can do : cd C:\Users\Username\Desktop or cd Desktop This one works if the directed folder is a sub folder of Username .Than you can use this code : start test.exe. hope this helps.Please send a feedback.

System() fails with return value 255/-1 (8 bit representation)

I have an executable, which has a few system commands (basically it does copying and running script files). When I test in standalone (launching the executable myself as with sudo) system() is working fine.
Now I integrate my executable with supervisord. Functionality of my executable is working fine, but the system() command fails with 255 / -1 (8 bit representation).
List of things I checked:
The current working directory of the process is correct
Supervisord and my process are running as root
chown of directory and file are root
Any other suggestions?
system("sudo cp ./Scripts/x.sh /tmp/");
sudo is the command to obtain superuser rights. It normally promts you for password (but under some circumstances, it skips it). Maybe it fails if it has no console to prompt you.
Anyway you should NOT do this. You sould just write system("cp ./Scripts/x.sh /tmp/") and start your program with root access (supervisord probably has a way to do that).

Permission denied running my own program on Linux? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
Improve this question
I have Ubuntu 9.4. I've built the program, some basic OpenGL. The program just makes a rotating square. Then run it and:
sh: /blabla permission denied.
And an empty main doesn't work:
int main()
{
return 0;
}
How can I make that disappear?
I had the same problem and it appeared that my partition was mounted as noexec
cat /etc/mtab
When I configured options in /etc/fstab I wrote exec,user but it appears that "user" option by default sets up "noexec". When I changed the order of these two to user,exec everything went back to normal!
Hope it helps.
How are you compiling it? Can you post the makefile? If you run
chmod +x myPorgram
./myProgram
something changes?
Check the mountpoint to see if it's mounted as noexec by running "mount"
I use CodeBlocks on Ubuntu and have had this exact problem MANY times.
what KermiDT said is exactly the solution (if i had enough rep points, i would have voted it up)
The "user" option by default sets up "noexec".
so in /etc/fstab just add ,exec after user.
i.e. mine looks like this:
/dev/sda6 /media/DATA vfat uid=kenny,gid=kenny,users,user,exec 0 0
Though, the spacingis a bit off... but you get the idea.
Apart from the above mentioned chmod +x file, another problem might be a missing library. To check the required libraries, use ldd:
$ ldd /bin/sh
linux-vdso.so.1 => (0x00007fffb43fe000)
libc.so.6 => /lib/libc.so.6 (0x00007fc4abe11000)
/lib64/ld-linux-x86-64.so.2 (0x00007fc4ac183000)
If one of these lines shows a missing library, you'll know what needs to be installed before you can run your program.
Another possibility is if your program is a script (shell, perl, python or other text-based program). The first line looks like:
#!/usr/bin/perl
If that file cannot be found, you'll get a permission denied error.
Couple of questions:
Are the permissions set correctly on the file?
Is the path to any interpreter set correctly?
You also get this problem when trying to execute 32-bit apps on a 64-bit system. Execute:
a. file (executable name)
b. uname -a
and check that both are either "i386" or "amd64".
If they are not the same, have a look at this article:
Try executing the command with strace to trace the successful system calls it makes and where it stops.
This is how you might launch it,
strace ./blabla
Do you get a "permission denied" error or something like "exec format error"? With chmod +rx on the file you should not hit "permission denied".
You should also make sure that your username is in the video group. Check the /etc/group and make sure that your username appears on the "video" line.