0

I use sublime text 4 on macOS. I have a custom C++ build to read from a input.txt file in current file path. but when I run my custom build, it shows

bash: /Users/jigyansu_nanda/Downloads/CP/input.txt: Permission denied

My custom C++ sublime-build is the following.

{
 
 "cmd":["bash", "-c", "g++-11 -Dlocal -std=c++17 -Wall '${file}' -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"],
 
 "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
 
 "working_dir": "${file_path}",
 
 "selector": "source.c, source.c++",
 
 "variants":
 
 [
 
   {
 
     "name": "Run",
 
     "cmd":["bash", "-c", "g++-11 -Dlocal -std=c++17 '${file}' -o '${file_path}/${file_base_name}' && bash -c '\"${file_path}/input.txt\" ; read'"]
 
   }
 
 ]
 
}

What can I do to get past this.

  • Welcome to SO. Do you have permissions set properly? Is it read-only? – ewokx Mar 29 '22 at 09:10
  • When i installed Sublime Text 4, it didn't ask for any permission. But now I go to the CP folder in my downloads and clicked on get info, and gave everyone permission to read and write, but the issue still persists. is there something I am missing ? – Jigyansu Nanda Mar 29 '22 at 09:30
  • Also before this, I used to handle reading and writing like from and to file inside the code.cpp file itself using freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); That worked properly. but now I want to make it default from build. – Jigyansu Nanda Mar 29 '22 at 09:35
  • `cmd` in builds is for running one single program and giving it the arguments it requires; what you are trying to execute here is a shell command; for that you use `shell_cmd` instead; see [the build system documenation](https://www.sublimetext.com/docs/build_systems.html#exec_options). `shell_cmd` takes the exact command string that you would type in the terminal, so there's no need to try and manually run bash. It also allows redirection. – OdatNurd Mar 29 '22 at 13:17
  • Thank you for your reply but I still am unable to do it. – Jigyansu Nanda Mar 29 '22 at 15:47
  • The second part of your second command is telling bash to execute a text file; if your text file doesn't have executable permissions, you can't execute it. That's an OS level issue, not a Sublime level issue. – OdatNurd Mar 29 '22 at 23:59
  • Thank you. Now I gave my input.txt and output.txt file rwx read, write and execution permission and the issue is gone. However I am getting a different issue, when trying to run build. It says the following on ST output. g++-11: warning: bash: linker input file unused because linking not done g++-11: error: bash: linker input file not found: No such file or directory – Jigyansu Nanda Mar 30 '22 at 00:27
  • That is not a Sublime issue; that's a tooling issue. You need to first work out exactly what it is you need to execute manually in your terminal to carry out the action that you want, and then you can tell Sublime how to do that same thing. – OdatNurd Mar 30 '22 at 01:12

0 Answers0