www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - system() without window

reply okibi <okibi ratedo.com> writes:
Hey,

Is it possible to run a command with the system() function without having the
program open up a command prompt until it finishes?

Thanks!
Jul 11 2007
parent reply Regan Heath <regan netmail.co.nz> writes:
okibi wrote:
 Hey,
 
 Is it possible to run a command with the system() function without having the
program open up a command prompt until it finishes?
 
 Thanks!
I doubt it.. but you can call CreateProcess and prevent the window appearing. Also there is popen which may prevent it. Both are more complicated than system but offer more flexibility too. Regan
Jul 11 2007
parent reply okibi <okibi ratedo.com> writes:
Is there documentation somewhere on how these work? Also, will they work on
both Windows and Linux?

Thanks!

Regan Heath Wrote:

 okibi wrote:
 Hey,
 
 Is it possible to run a command with the system() function without having the
program open up a command prompt until it finishes?
 
 Thanks!
I doubt it.. but you can call CreateProcess and prevent the window appearing. Also there is popen which may prevent it. Both are more complicated than system but offer more flexibility too. Regan
Jul 11 2007
parent reply Regan Heath <regan netmail.co.nz> writes:
okibi wrote:
 Is there documentation somewhere on how these work? Also, will they work on
both Windows and Linux?
 
 Thanks!
 
 Regan Heath Wrote:
 
 okibi wrote:
 Hey,

 Is it possible to run a command with the system() function without having the
program open up a command prompt until it finishes?

 Thanks!
I doubt it.. but you can call CreateProcess and prevent the window appearing. Also there is popen which may prevent it. Both are more complicated than system but offer more flexibility too. Regan
Popen; http://www.opengroup.org/pubs/online/7908799/xsh/popen.html You will need to do something like: extern(C) FILE *popen(const char *command, const char *mode); in your D source file before you can call it. See dm\include\stdio.h for the function declaration. Any function you can find in the dm include directories can be called like this. I wrote a ProcessStream using CreateProcess etc which worked on both windows and linux (although there may have been a few bugs to deal with): http://www.digitalmars.com/d/archives/digitalmars/D/learn/internal_error_toObjFile_7911.html You can find stuff like this by searching the archives here: http://www.digitalmars.com/d/archives/digitalmars/D/index.html http://www.digitalmars.com/d/archives/digitalmars/D/learn/index.html ..etc.. Regan
Jul 11 2007
next sibling parent reply okibi <okibi ratedo.com> writes:
I tried your method for popen and i get "Symbol undefined" errors. I also tried
this code:

extern (C) {
	typedef void FILE;
	FILE* popen(char* cmd, char* type);
	int pclose(FILE* stream);
}

and get the same errors.

Any ideas?

Regan Heath Wrote:

 okibi wrote:
 Is there documentation somewhere on how these work? Also, will they work on
both Windows and Linux?
 
 Thanks!
 
 Regan Heath Wrote:
 
 okibi wrote:
 Hey,

 Is it possible to run a command with the system() function without having the
program open up a command prompt until it finishes?

 Thanks!
I doubt it.. but you can call CreateProcess and prevent the window appearing. Also there is popen which may prevent it. Both are more complicated than system but offer more flexibility too. Regan
Popen; http://www.opengroup.org/pubs/online/7908799/xsh/popen.html You will need to do something like: extern(C) FILE *popen(const char *command, const char *mode); in your D source file before you can call it. See dm\include\stdio.h for the function declaration. Any function you can find in the dm include directories can be called like this. I wrote a ProcessStream using CreateProcess etc which worked on both windows and linux (although there may have been a few bugs to deal with): http://www.digitalmars.com/d/archives/digitalmars/D/learn/internal_error_toObjFile_7911.html You can find stuff like this by searching the archives here: http://www.digitalmars.com/d/archives/digitalmars/D/index.html http://www.digitalmars.com/d/archives/digitalmars/D/learn/index.html ..etc.. Regan
Jul 11 2007
parent reply Regan Heath <regan netmail.co.nz> writes:
okibi wrote:
 I tried your method for popen and i get "Symbol undefined" errors. I also
tried this code:
 
 extern (C) {
 	typedef void FILE;
 	FILE* popen(char* cmd, char* type);
 	int pclose(FILE* stream);
 }
 
 and get the same errors.
 
 Any ideas?
Ahh, I was mistaken; popen only works on UNIX. You need to code up something with CreateProcess. I recall someone else posted a popen implementation for windows once.. http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.com&group=digitalmars.D&artnum=14470 Maybe that will help. Regan
Jul 11 2007
parent okibi <okibi ratedo.com> writes:
Does system() (within std.process) not work on linux? I was under the
impression that it did.

I'll look into that, thanks!

Regan Heath Wrote:

 okibi wrote:
 I tried your method for popen and i get "Symbol undefined" errors. I also
tried this code:
 
 extern (C) {
 	typedef void FILE;
 	FILE* popen(char* cmd, char* type);
 	int pclose(FILE* stream);
 }
 
 and get the same errors.
 
 Any ideas?
Ahh, I was mistaken; popen only works on UNIX. You need to code up something with CreateProcess. I recall someone else posted a popen implementation for windows once.. http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.com&group=digitalmars.D&artnum=14470 Maybe that will help. Regan
Jul 11 2007
prev sibling parent okibi <okibi ratedo.com> writes:
I tried your method for popen and i get "Symbol undefined" errors. I also tried
this code:

extern (C) {
	typedef void FILE;
	FILE* popen(char* cmd, char* type);
	int pclose(FILE* stream);
}

and get the same errors.

Any ideas?

Regan Heath Wrote:

 okibi wrote:
 Is there documentation somewhere on how these work? Also, will they work on
both Windows and Linux?
 
 Thanks!
 
 Regan Heath Wrote:
 
 okibi wrote:
 Hey,

 Is it possible to run a command with the system() function without having the
program open up a command prompt until it finishes?

 Thanks!
I doubt it.. but you can call CreateProcess and prevent the window appearing. Also there is popen which may prevent it. Both are more complicated than system but offer more flexibility too. Regan
Popen; http://www.opengroup.org/pubs/online/7908799/xsh/popen.html You will need to do something like: extern(C) FILE *popen(const char *command, const char *mode); in your D source file before you can call it. See dm\include\stdio.h for the function declaration. Any function you can find in the dm include directories can be called like this. I wrote a ProcessStream using CreateProcess etc which worked on both windows and linux (although there may have been a few bugs to deal with): http://www.digitalmars.com/d/archives/digitalmars/D/learn/internal_error_toObjFile_7911.html You can find stuff like this by searching the archives here: http://www.digitalmars.com/d/archives/digitalmars/D/index.html http://www.digitalmars.com/d/archives/digitalmars/D/learn/index.html ..etc.. Regan
Jul 11 2007