Reputation: 1573
I am using sublime in linux I am trying to compile and run my c++ program from sublime directly with INPUT taken from a file rather than STDIN.
Please help me with the code to be written in sublime build-file.
I got this code but its not working i think its for windows not for linux:
{
"cmd" : ["g++", "$file_name", "-o", "${file_base_name}.exe"],
"selector" : "source.c",
"shell":true,
"working_dir" : "$file_path",
"variants": [
{
"cmd": ["${file_base_name}" , "<" , "input.txt"],
"shell": true,
"name": "Run",
"working_dir" : "$file_path"
}
]
}
Upvotes: 1
Views: 2225
Reputation: 1143
I'll just add a config I use to load input from the file and display output in Sublime console ("Run in") or send output to other file ("Run in out"). Maybe someone will find it useful. (works for both Windows and Ubuntu)
{
"shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\"",
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++",
"variants":
[
{
"name": "Run in",
"shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\" <$file_base_name.in"
},
{
"name": "Run in out",
"shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\" <$file_base_name.in >$file_base_name.txt"
}
]
}
Upvotes: 1
Reputation: 1573
This is the final code which one needs to write in build system of sublime to compile and run taking input from a file.
{
"cmd": ["g++ -Wall ${file} -o ${file_base_name}"],
"working_dir": "${file_path}",
"selector": "source.c++",
"shell": true,
"working_dir" : "$file_path",
"variants": [
{
"cmd": [ "${file_path}/${file_base_name}<input.txt"],
"shell": true,
"name": "Run",
"working_dir" : "$file_path"
}
]
}
Thanks a lot MattDMo.
Upvotes: 3
Reputation: 102902
I suspect the reason it's not working is because g++
is creating a .exe
file, and the build system is only looking for the source.c
scope, whereas your code may be source.c++
. Change the first two lines to the following:
"cmd" : ["g++", "$file", "-o", "${file_path}/${file_base_name}"],
"selector" : "source.c, source.c++",
and you should be all set.
Upvotes: 1