system and system2 in R [Software]
❝ I need to spawn the gcc compiler now and then from within R. That's easily done with the system
or system2
functions. But I also need to capture the console output that is produced by gcc. And that's my trouble.
❝
❝ So, along the same lines I hope to execute gcc as:
❝ x=system(command="gcc -Wall -O2 myfile.c -o Target", intern=T)
❝ print(x)
❝
❝ and even though gcc does the compilation nicely, x is -surprisingly to me- empty. It is not because gcc does not spit out info and the command is fully ok [foot note 1]. gcc prints plenty lines to the console. I just do not know how to capture them with R.
I tried this
#include <stdio.h>
int main() {
printf("Hello, world!\n");
return 0;
}
hw.c
gcc-x86_64-w64 10.3.0 called from R 4.1.2:
system(command = "gcc -Wall -O2 hw.c -o hw", intern = TRUE)
character(0)
hw.exe
In R 4.2.1:
system(command = "hw", intern = TRUE)
[1] "Hello, world!"
PS: This thread is perfectly On-topic.
Dif-tor heh smusma 🖖🏼 Довге життя Україна!
Helmut Schütz
The quality of responses received is directly proportional to the quality of the question asked. 🚮
Science Quotes
Complete thread:
- system and system2 in R ElMaestro 2022-08-29 22:29 [Software]
- system and system2 in RHelmut 2022-08-30 01:10
- system and system2 in R ElMaestro 2022-08-30 08:52
- system and system2 in R Helmut 2022-08-30 11:25
- processx package mittyri 2022-08-31 17:50
- system and system2 in R ElMaestro 2022-08-30 08:52
- tryCatch in R mittyri 2022-08-31 17:53
- tryCatch in R ElMaestro 2022-09-01 10:33
- tryCatch in R mittyri 2022-09-01 14:07
- tryCatch in R ElMaestro 2022-09-01 10:33
- system and system2 in RHelmut 2022-08-30 01:10