* Capturing output from C/C++
@ 2015-03-05 16:27 Roger Mason
2015-03-05 18:00 ` John Kitchin
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Roger Mason @ 2015-03-05 16:27 UTC (permalink / raw)
To: emacs-orgmode
Hello,
I have a short C++ program:
#+BEGIN_SRC cpp :flags -lm :results output
#include <iostream>
#include <fstream>
#include <cmath> // for ceil
#include <cstdlib> // for atof
double f (double fv, double o, int i) {
return fv / 2.0 + (1.0 - o) * fv * i;
}
int num (double d, double fv, double o) {
return (int)ceil( d / ((1.0 - o) * fv ));
}
int main (int argc, char* argv[]) {
if ( argc < 6 ) {
std::cout << "Usage:\n" << std::endl;
std::cout << "grid w fovx ox h fovy oy\n" << std::endl;
return 1;
}
...
#+END_SRC
that outputs some data to stdout.
So far I have not been able to capture the output of the program back
into to my org buffer.
Is that possible and, if so, how?
Thanks,
Roger
Org-mode version 8.2.6
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Capturing output from C/C++
2015-03-05 16:27 Capturing output from C/C++ Roger Mason
@ 2015-03-05 18:00 ` John Kitchin
2015-03-05 18:06 ` Thierry Banel
2015-03-05 18:32 ` Nick Dokos
2 siblings, 0 replies; 4+ messages in thread
From: John Kitchin @ 2015-03-05 18:00 UTC (permalink / raw)
To: Roger Mason; +Cc: emacs-orgmode
I think you need to tangle the file, compile it and run the executable
in a shell block.
Here is a Fortran example:
http://kitchingroup.cheme.cmu.edu/blog/2014/02/04/Literate-programming-example-with-Fortran-and-org-mode/
I have done similar things with C, java, etc... before.
I don't know of a built in way to type C-c C-c and have it do all those
things for you.
Roger Mason writes:
> Hello,
>
> I have a short C++ program:
>
> #+BEGIN_SRC cpp :flags -lm :results output
> #include <iostream>
> #include <fstream>
> #include <cmath> // for ceil
> #include <cstdlib> // for atof
>
> double f (double fv, double o, int i) {
> return fv / 2.0 + (1.0 - o) * fv * i;
> }
>
> int num (double d, double fv, double o) {
> return (int)ceil( d / ((1.0 - o) * fv ));
> }
>
> int main (int argc, char* argv[]) {
> if ( argc < 6 ) {
> std::cout << "Usage:\n" << std::endl;
> std::cout << "grid w fovx ox h fovy oy\n" << std::endl;
> return 1;
> }
> ...
> #+END_SRC
>
> that outputs some data to stdout.
>
> So far I have not been able to capture the output of the program back
> into to my org buffer.
>
> Is that possible and, if so, how?
>
> Thanks,
> Roger
> Org-mode version 8.2.6
--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Capturing output from C/C++
2015-03-05 16:27 Capturing output from C/C++ Roger Mason
2015-03-05 18:00 ` John Kitchin
@ 2015-03-05 18:06 ` Thierry Banel
2015-03-05 18:32 ` Nick Dokos
2 siblings, 0 replies; 4+ messages in thread
From: Thierry Banel @ 2015-03-05 18:06 UTC (permalink / raw)
To: emacs-orgmode
It might be due to the return 1; statement.
Change it to return 0; and try again.
Le 05/03/2015 17:27, Roger Mason a écrit :
> Hello,
>
> I have a short C++ program:
>
> #+BEGIN_SRC cpp :flags -lm :results output
> #include <iostream>
> #include <fstream>
> #include <cmath> // for ceil
> #include <cstdlib> // for atof
>
> double f (double fv, double o, int i) {
> return fv / 2.0 + (1.0 - o) * fv * i;
> }
>
> int num (double d, double fv, double o) {
> return (int)ceil( d / ((1.0 - o) * fv ));
> }
>
> int main (int argc, char* argv[]) {
> if ( argc < 6 ) {
> std::cout << "Usage:\n" << std::endl;
> std::cout << "grid w fovx ox h fovy oy\n" << std::endl;
> return 1;
> }
> ...
> #+END_SRC
>
> that outputs some data to stdout.
>
> So far I have not been able to capture the output of the program back
> into to my org buffer.
>
> Is that possible and, if so, how?
>
> Thanks,
> Roger
> Org-mode version 8.2.6
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Capturing output from C/C++
2015-03-05 16:27 Capturing output from C/C++ Roger Mason
2015-03-05 18:00 ` John Kitchin
2015-03-05 18:06 ` Thierry Banel
@ 2015-03-05 18:32 ` Nick Dokos
2 siblings, 0 replies; 4+ messages in thread
From: Nick Dokos @ 2015-03-05 18:32 UTC (permalink / raw)
To: emacs-orgmode
Roger Mason <rmason@mun.ca> writes:
> Hello,
>
> I have a short C++ program:
>
> #+BEGIN_SRC cpp :flags -lm :results output
> #include <iostream>
> #include <fstream>
> #include <cmath> // for ceil
> #include <cstdlib> // for atof
>
> double f (double fv, double o, int i) {
> return fv / 2.0 + (1.0 - o) * fv * i;
> }
>
> int num (double d, double fv, double o) {
> return (int)ceil( d / ((1.0 - o) * fv ));
> }
>
> int main (int argc, char* argv[]) {
> if ( argc < 6 ) {
> std::cout << "Usage:\n" << std::endl;
> std::cout << "grid w fovx ox h fovy oy\n" << std::endl;
> return 1;
> }
> ...
> #+END_SRC
>
> that outputs some data to stdout.
>
> So far I have not been able to capture the output of the program back
> into to my org buffer.
>
> Is that possible and, if so, how?
>
You call your program with no arguments, which means that it returns 1,
which is interpreted as an error. Try returning 0 or fix the call so
that it goes through the path that returns 0.
Nick
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-03-05 18:33 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-05 16:27 Capturing output from C/C++ Roger Mason
2015-03-05 18:00 ` John Kitchin
2015-03-05 18:06 ` Thierry Banel
2015-03-05 18:32 ` Nick Dokos
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).