简体   繁体   中英

how to run a c code from a usb pendrive?

I had to run few code written by me on multiple computers, and once its done (complete compile and run) the code was not suppose to be present on those computers.
Previously i was able to accomplish this with codes written in python. By placing the python code inside the pen-drive and directly run them from the pen-drive itself.

say, I had a python codes that was placed inside my pen-drive( 5A30-C211 ).

/media/5A30-C211$ python sample_code.py

i was able to get the output (where /media/5A30-C211 was my pen-drive). But i have some c code now. And when i do the same for ac code.

/media/5A30-C211$ gcc sample_code.c -o sample_code
/media/5A30-C211$ ./sample_code
bash: ./sample_code: Permission denied

as i saw the word Permission denied , i added sudo to the compile and run command. I get the output as command not found .

Question is: is there any way i could run ac code from a usb flash stick / pen-drive without using sudo like i did with python?

Your file needs executable permission ( chmod +x ), but since you're running vfat drive that doesn't support posix permissions chmod isn't going to work.

You need to remount the drive with proper permissions.

mount -t vfat -o umask=022,gid=<users group id>,uid=<user id> \
    /dev/<pendrive device> /mnt/<pendrive mnt point>

To run a compiled program it needs to have the executable permission set on the file. The issue here is that your pendrive is formatted as vfat, which is a FS coming from the Windows world. As such it does not have support for the Unix permission system and you cannot set the executable permission on the file.

You have two options to fix your issue:

  • Format the pendrive as a Unix FS like ext4.
  • Copy your program to a temporary folder on the PC, give it the executable permission (chmod +x ) and remove it afterwards.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM