digitalmars.D.learn - How to execute external program and process its output?
- Marcin Kuszczak (10/10) Jul 31 2006 Hello!
- Pragma (8/21) Jul 31 2006 Marcin,
- Marcin Kuszczak (24/27) Jul 31 2006 I had to modify a little bit program, but then it works - thanks a lot!
- Tom S (7/34) Jul 31 2006 extern (C) {
- Marcin Kuszczak (8/44) Jul 31 2006 Thanks! using C was easier than I thought...
- BCS (4/17) Jul 31 2006 IIRC somewhere back a few months ago, someone made a stream object that
- Marcin Kuszczak (6/25) Jul 31 2006 How to find it? is it somewere on Wiki?
- BCS (4/31) Jul 31 2006 These look somewhat like what I remember.
- Regan Heath (4/21) Jul 31 2006 Oh, me, me, pick me! Attached are the classes I wrote back then :)
- Marcin Kuszczak (8/33) Aug 01 2006 Thanks! I will give it a try.
Hello! I am trying to execute external command from D program, and then process its output. spawnvp() doesn't seem to be enough as it does not return output, but just status as int. How to achieve it in D (I don't know method also in C(++), so even this will help <g>)? --- Regards Marcin Kuszczak (Aarti_pl)
Jul 31 2006
Marcin Kuszczak wrote:Hello! I am trying to execute external command from D program, and then process its output. spawnvp() doesn't seem to be enough as it does not return output, but just status as int. How to achieve it in D (I don't know method also in C(++), so even this will help <g>)? --- Regards Marcin Kuszczak (Aarti_pl)Marcin, I don't know the "correct" way to do this, but perhaps I can offer a short-term hack to get you by? char[] commandline = "echo 'hello world' > output.txt"; std.process.system(commandline); writefln("result: %s",std.file.read("output.txt")); Sure its not pretty, but it does work.
Jul 31 2006
Pragma wrote:char[] commandline = "echo 'hello world' > output.txt"; std.process.system(commandline); writefln("result: %s",std.file.read("output.txt"));I had to modify a little bit program, but then it works - thanks a lot! -- void main() { char[] commandline = "svn info >output.txt 2>&1"; std.process.system(commandline); char[] result = cast(char[])(std.file.read("output.txt")); writefln("result: %s", result); } -- In the meantime I found also that there should be functions on C API -- #include <stdio.h> FILE *popen( const char *command, const char *type); int pclose( FILE *stream); -- but as I see it is not wrapped by D. I don't have any idea how to do it. If anyone can give some more info it would be great. BTW if D wants to be also language for scripting, it should have such a possibility in standard library. -- Regards Marcin Kuszczak (Aarti_pl)
Jul 31 2006
Marcin Kuszczak wrote:Pragma wrote:extern (C) { typedef void FILE; FILE* popen(char* cmd, char* type); int pclose(FILE* stream); } should workchar[] commandline = "echo 'hello world' > output.txt"; std.process.system(commandline); writefln("result: %s",std.file.read("output.txt"));I had to modify a little bit program, but then it works - thanks a lot! -- void main() { char[] commandline = "svn info >output.txt 2>&1"; std.process.system(commandline); char[] result = cast(char[])(std.file.read("output.txt")); writefln("result: %s", result); } -- In the meantime I found also that there should be functions on C API -- #include <stdio.h> FILE *popen( const char *command, const char *type); int pclose( FILE *stream); -- but as I see it is not wrapped by D. I don't have any idea how to do it. If anyone can give some more info it would be great.
Jul 31 2006
Tom S wrote:Marcin Kuszczak wrote:Thanks! using C was easier than I thought... (Second method still does not work for me, but it is just a mater of time :-) ) -- Regards Marcin Kuszczak (Aarti_pl)Pragma wrote:extern (C) { typedef void FILE; FILE* popen(char* cmd, char* type); int pclose(FILE* stream); } should workchar[] commandline = "echo 'hello world' > output.txt"; std.process.system(commandline); writefln("result: %s",std.file.read("output.txt"));I had to modify a little bit program, but then it works - thanks a lot! -- void main() { char[] commandline = "svn info >output.txt 2>&1"; std.process.system(commandline); char[] result = cast(char[])(std.file.read("output.txt")); writefln("result: %s", result); } -- In the meantime I found also that there should be functions on C API -- #include <stdio.h> FILE *popen( const char *command, const char *type); int pclose( FILE *stream); -- but as I see it is not wrapped by D. I don't have any idea how to do it. If anyone can give some more info it would be great.
Jul 31 2006
Marcin Kuszczak wrote:Hello! I am trying to execute external command from D program, and then process its output. spawnvp() doesn't seem to be enough as it does not return output, but just status as int. How to achieve it in D (I don't know method also in C(++), so even this will help <g>)? --- Regards Marcin Kuszczak (Aarti_pl)IIRC somewhere back a few months ago, someone made a stream object that did just what you want. You could even write to the program's standard input by outputting to the stream.
Jul 31 2006
BCS wrote:Marcin Kuszczak wrote:How to find it? is it somewere on Wiki? -- Regards Marcin Kuszczak (Aarti_pl)Hello! I am trying to execute external command from D program, and then process its output. spawnvp() doesn't seem to be enough as it does not return output, but just status as int. How to achieve it in D (I don't know method also in C(++), so even this will help <g>)? --- Regards Marcin Kuszczak (Aarti_pl)IIRC somewhere back a few months ago, someone made a stream object that did just what you want. You could even write to the program's standard input by outputting to the stream.
Jul 31 2006
Marcin Kuszczak wrote:BCS wrote:These look somewhat like what I remember. http://www.digitalmars.com/d/archives/digitalmars/D/29556.html http://www.digitalmars.com/d/archives/digitalmars/D/learn/542.htmlMarcin Kuszczak wrote:How to find it? is it somewere on Wiki?Hello! I am trying to execute external command from D program, and then process its output. spawnvp() doesn't seem to be enough as it does not return output, but just status as int. How to achieve it in D (I don't know method also in C(++), so even this will help <g>)? --- Regards Marcin Kuszczak (Aarti_pl)IIRC somewhere back a few months ago, someone made a stream object that did just what you want. You could even write to the program's standard input by outputting to the stream.
Jul 31 2006
On Mon, 31 Jul 2006 15:53:00 -0700, BCS <BCS pathlink.com> wrote:Marcin Kuszczak wrote:Oh, me, me, pick me! Attached are the classes I wrote back then :) Let me know if you have any trouble. ReganHello! I am trying to execute external command from D program, and then process its output. spawnvp() doesn't seem to be enough as it does not return output, but just status as int. How to achieve it in D (I don't know method also in C(++), so even this will help <g>)? --- Regards Marcin Kuszczak (Aarti_pl)IIRC somewhere back a few months ago, someone made a stream object that did just what you want. You could even write to the program's standard input by outputting to the stream.
Jul 31 2006
Regan Heath wrote:On Mon, 31 Jul 2006 15:53:00 -0700, BCS <BCS pathlink.com> wrote:Thanks! I will give it a try. It would be awesome if such a class could find its way into the standard library... -- Regards Marcin Kuszczak (Aarti_pl)Marcin Kuszczak wrote:Oh, me, me, pick me! Attached are the classes I wrote back then :) Let me know if you have any trouble. ReganHello! I am trying to execute external command from D program, and then process its output. spawnvp() doesn't seem to be enough as it does not return output, but just status as int. How to achieve it in D (I don't know method also in C(++), so even this will help <g>)? --- Regards Marcin Kuszczak (Aarti_pl)IIRC somewhere back a few months ago, someone made a stream object that did just what you want. You could even write to the program's standard input by outputting to the stream.
Aug 01 2006