-
Notifications
You must be signed in to change notification settings - Fork 204
/
run-c-cpp.nu
27 lines (26 loc) · 761 Bytes
/
run-c-cpp.nu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Runs C code via GCC without leaving a file behind
def rcc [
file: path # The file to run
] {
# Remove exe if still exists
rm $"($file).exe" --permanent --force
# Compile code to exe
^gcc ("." | path join $file | path expand) -o ("." | path join $"($file).exe" | path expand)
# Execute exe
^$"($file).exe"
# Remove exe
rm $"($file).exe" --permanent --force
}
# Runs C++ code via g++ without leaving a file behind
def r++ [
file: path # The file to run
] {
# Remove exe if still exists
rm $"($file).exe" --permanent --force
# Compile code to exe
^g++ ("." | path join $file | path expand) -o ("." | path join $"($file).exe" | path expand)
# Execute exe
^$"($file).exe"
# Remove exe
rm $"($file).exe" --permanent --force
}