www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Reagan: CreateProcess()?

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

I took your suggestion about getting system() to run without a window by
creating a CreateProcess(). I looked at your example on:

http://www.digitalmars.com/d/archives/digitalmars/D/29556.html

I can't get it to compile! I'm getting an error for expecting type ulong on
line 107 in your pipestream.d file.

Any ideas?

Thanks!
Jul 13 2007
next sibling parent reply Regan Heath <regan netmail.co.nz> writes:
okibi wrote:
 Hey Reagan,
 
 I took your suggestion about getting system() to run without a window by
creating a CreateProcess(). I looked at your example on:
 
 http://www.digitalmars.com/d/archives/digitalmars/D/29556.html
 
 I can't get it to compile! I'm getting an error for expecting type ulong on
line 107 in your pipestream.d file.
 
 Any ideas?
Change seek to: override ulong seek(long offset, SeekPos whence) { assertSeekable(); return 0; } The pipestream isn't seekable so it never returns. After doing that you get a problem with: HANDLE write = INVALID_HANDLE_VALUE; HANDLE read = INVALID_HANDLE_VALUE; just remove the "= INVALID.." it's not really necessary as the constructor always assigns values to these. There are several string/char[] changes, eg. 1) class ProcessException : Exception { version(Windows) { this(string msg) { super(msg ~ ": " ~ sysErrorString(GetLastError())); } } version(linux) { //for some reason getErrno does not link for me? this(string msg) { super(msg ~ ": " ~ std.string.toString(strerror(getErrno()))); } } } 2) string readLine() { return pout.readLine(); } string readError() { return perr.readLine(); } void writeLine(string line) { pin.writeLine(line); } After that I think it should compile, I can't guarantee this code works however ;) Tango has a tango.sys.Pipe and tango.sys.Process which probably do very similar stuff. Regan
Jul 13 2007
parent reply okibi <okibi ratedo.com> writes:
Well, I can compile and use the code now, but it still makes that darn window
pop up. Is there ANYWAY to keep the black window from popping up?

Thanks!

Regan Heath Wrote:

 okibi wrote:
 Hey Reagan,
 
 I took your suggestion about getting system() to run without a window by
creating a CreateProcess(). I looked at your example on:
 
 http://www.digitalmars.com/d/archives/digitalmars/D/29556.html
 
 I can't get it to compile! I'm getting an error for expecting type ulong on
line 107 in your pipestream.d file.
 
 Any ideas?
Change seek to: override ulong seek(long offset, SeekPos whence) { assertSeekable(); return 0; } The pipestream isn't seekable so it never returns. After doing that you get a problem with: HANDLE write = INVALID_HANDLE_VALUE; HANDLE read = INVALID_HANDLE_VALUE; just remove the "= INVALID.." it's not really necessary as the constructor always assigns values to these. There are several string/char[] changes, eg. 1) class ProcessException : Exception { version(Windows) { this(string msg) { super(msg ~ ": " ~ sysErrorString(GetLastError())); } } version(linux) { //for some reason getErrno does not link for me? this(string msg) { super(msg ~ ": " ~ std.string.toString(strerror(getErrno()))); } } } 2) string readLine() { return pout.readLine(); } string readError() { return perr.readLine(); } void writeLine(string line) { pin.writeLine(line); } After that I think it should compile, I can't guarantee this code works however ;) Tango has a tango.sys.Pipe and tango.sys.Process which probably do very similar stuff. Regan
Jul 13 2007
parent reply Regan Heath <regan netmail.co.nz> writes:
okibi wrote:
 Well, I can compile and use the code now, but it still makes that darn window
pop up. Is there ANYWAY to keep the black window from popping up?
What are you running? Show me your code which uses Process. Regan
Jul 13 2007
parent reply okibi <okibi ratedo.com> writes:
Well, I'm trying to open notepad. I just used your code and replace the Process
command being issued.

Thanks!

Regan Heath Wrote:

 okibi wrote:
 Well, I can compile and use the code now, but it still makes that darn window
pop up. Is there ANYWAY to keep the black window from popping up?
What are you running? Show me your code which uses Process. Regan
Jul 13 2007
parent Regan Heath <regan netmail.co.nz> writes:
okibi wrote:
 Well, I'm trying to open notepad. I just used your code and replace the
Process command being issued.
The idea was that you do something like: Process notepad = new Process(r"c:\windows\notepad.exe"); but when I did that I got a few more char[]/string errors, fixing those gives me an application error for notepad, not sure why (probably it expects certain enviroment variables or something, who knows) So, I don't get the same results as you :( I suggest you look at Tango, try and use the Process class in there. I'm busy this weekend otherwise I'd try and tidy it up and get it working. I might have a look at it next week some time. Till then I'm afraid you're on your own. Regan
Jul 13 2007
prev sibling parent reply Clay Smith <clayasaurus gmail.com> writes:
okibi wrote:
 Hey Reagan,
 
 I took your suggestion about getting system() to run without a window by
creating a CreateProcess(). I looked at your example on:
 
 http://www.digitalmars.com/d/archives/digitalmars/D/29556.html
 
 I can't get it to compile! I'm getting an error for expecting type ulong on
line 107 in your pipestream.d file.
 
 Any ideas?
 
 Thanks!
Here you go: Windows info: http://paste.dprogramming.com/dptyg7pt.php Create Process: http://paste.dprogramming.com/dpsgva0j.php You can use execProcess or my ChildProcesses class. ~ Clay
Jul 16 2007
parent reply okibi <okibi ratedo.com> writes:
The globals module is missing. Where can I find it?

Thanks!

Clay Smith Wrote:

 okibi wrote:
 Hey Reagan,
 
 I took your suggestion about getting system() to run without a window by
creating a CreateProcess(). I looked at your example on:
 
 http://www.digitalmars.com/d/archives/digitalmars/D/29556.html
 
 I can't get it to compile! I'm getting an error for expecting type ulong on
line 107 in your pipestream.d file.
 
 Any ideas?
 
 Thanks!
Here you go: Windows info: http://paste.dprogramming.com/dptyg7pt.php Create Process: http://paste.dprogramming.com/dpsgva0j.php You can use execProcess or my ChildProcesses class. ~ Clay
Jul 24 2007
parent reply okibi <okibi ratedo.com> writes:
Well, I can take out the import and comment out off the directory settings and
the function works, however I need to give the full path of the command. 

However, it won't let me run batch scripts through the function at all. And for
commands that take arguments, I seem to need to send it through a cmd prompt,
which opens a window obviously. The only thing that really helped was the
ability to choose whether to wait for the exit code or not.

Is the fact that the directory stuff is missing as well as the globals file
causing this issue?

thanks!

okibi Wrote:

 The globals module is missing. Where can I find it?
 
 Thanks!
 
 Clay Smith Wrote:
 
 okibi wrote:
 Hey Reagan,
 
 I took your suggestion about getting system() to run without a window by
creating a CreateProcess(). I looked at your example on:
 
 http://www.digitalmars.com/d/archives/digitalmars/D/29556.html
 
 I can't get it to compile! I'm getting an error for expecting type ulong on
line 107 in your pipestream.d file.
 
 Any ideas?
 
 Thanks!
Here you go: Windows info: http://paste.dprogramming.com/dptyg7pt.php Create Process: http://paste.dprogramming.com/dpsgva0j.php You can use execProcess or my ChildProcesses class. ~ Clay
Jul 25 2007
parent reply Clay Smith <clayasaurus gmail.com> writes:
The globals file is not necessary, just replace globals.programDir with 
the location of the program directory as a char[].

execProcess(char[] program, char[] args, bool requireExitCode=true)

you don't need to run from cmd prompt to set program arguments, just do

execProcess("C:\svn\svn.exe", "co svn.dsource.org");

For batch scripts, use C:\systemwhatever\cmd.exe as program name and 
batch.bat as the argument, that is supposed to work.

~ Clay

okibi wrote:
 Well, I can take out the import and comment out off the directory settings and
the function works, however I need to give the full path of the command. 
 
 However, it won't let me run batch scripts through the function at all. And
for commands that take arguments, I seem to need to send it through a cmd
prompt, which opens a window obviously. The only thing that really helped was
the ability to choose whether to wait for the exit code or not.
 
 Is the fact that the directory stuff is missing as well as the globals file
causing this issue?
 
 thanks!
 
 okibi Wrote:
 
 The globals module is missing. Where can I find it?

 Thanks!

 Clay Smith Wrote:

 okibi wrote:
 Hey Reagan,

 I took your suggestion about getting system() to run without a window by
creating a CreateProcess(). I looked at your example on:

 http://www.digitalmars.com/d/archives/digitalmars/D/29556.html

 I can't get it to compile! I'm getting an error for expecting type ulong on
line 107 in your pipestream.d file.

 Any ideas?

 Thanks!
Here you go: Windows info: http://paste.dprogramming.com/dptyg7pt.php Create Process: http://paste.dprogramming.com/dpsgva0j.php You can use execProcess or my ChildProcesses class. ~ Clay
Sep 05 2007
parent reply okibi <okibi ratedo.com> writes:
Firstly, this only works on Windows, which is ok as system() doesn't open a
terminal window on Linux.

The problem is that I'm hitting a batch file. When I set the program to point
to cmd.exe, it will cause a command prompt window to open to run the command,
so back to square one.

Clay Smith Wrote:

 The globals file is not necessary, just replace globals.programDir with 
 the location of the program directory as a char[].
 
 execProcess(char[] program, char[] args, bool requireExitCode=true)
 
 you don't need to run from cmd prompt to set program arguments, just do
 
 execProcess("C:\svn\svn.exe", "co svn.dsource.org");
 
 For batch scripts, use C:\systemwhatever\cmd.exe as program name and 
 batch.bat as the argument, that is supposed to work.
 
 ~ Clay
 
 okibi wrote:
 Well, I can take out the import and comment out off the directory settings and
the function works, however I need to give the full path of the command. 
 
 However, it won't let me run batch scripts through the function at all. And
for commands that take arguments, I seem to need to send it through a cmd
prompt, which opens a window obviously. The only thing that really helped was
the ability to choose whether to wait for the exit code or not.
 
 Is the fact that the directory stuff is missing as well as the globals file
causing this issue?
 
 thanks!
 
 okibi Wrote:
 
 The globals module is missing. Where can I find it?

 Thanks!

 Clay Smith Wrote:

 okibi wrote:
 Hey Reagan,

 I took your suggestion about getting system() to run without a window by
creating a CreateProcess(). I looked at your example on:

 http://www.digitalmars.com/d/archives/digitalmars/D/29556.html

 I can't get it to compile! I'm getting an error for expecting type ulong on
line 107 in your pipestream.d file.

 Any ideas?

 Thanks!
Here you go: Windows info: http://paste.dprogramming.com/dptyg7pt.php Create Process: http://paste.dprogramming.com/dpsgva0j.php You can use execProcess or my ChildProcesses class. ~ Clay
Sep 26 2007
parent reply Regan Heath <regan netmail.co.nz> writes:
okibi wrote:
 Firstly, this only works on Windows, which is ok as system() doesn't open a
terminal window on Linux.
 
 The problem is that I'm hitting a batch file. When I set the program to point
to cmd.exe, it will cause a command prompt window to open to run the command,
so back to square one.
What creation flags is it using? CREATE_NO_WINDOW or DETACHED_PROCESS? http://msdn2.microsoft.com/en-us/library/ms684863.aspx Regan
Sep 26 2007
parent reply okibi <okibi ratedo.com> writes:
Sorry, I'm not all too familiar with CreateProcess functions.

From what I can tell, it's doing a CREATE_NEW_CONSOLE. Changing it to
CREATE_NO_WINDOW or DETACHED_PROCESS doesn't work.

Regan Heath Wrote:

 okibi wrote:
 Firstly, this only works on Windows, which is ok as system() doesn't open a
terminal window on Linux.
 
 The problem is that I'm hitting a batch file. When I set the program to point
to cmd.exe, it will cause a command prompt window to open to run the command,
so back to square one.
What creation flags is it using? CREATE_NO_WINDOW or DETACHED_PROCESS? http://msdn2.microsoft.com/en-us/library/ms684863.aspx Regan
Sep 26 2007
parent reply okibi <okibi ratedo.com> writes:
I take that back, CREATE_NO_WINDOW fails (undefined identifier) and
DETACHED_PROCESS works, but the window still opens.

okibi Wrote:

 Sorry, I'm not all too familiar with CreateProcess functions.
 
 From what I can tell, it's doing a CREATE_NEW_CONSOLE. Changing it to
CREATE_NO_WINDOW or DETACHED_PROCESS doesn't work.
 
 Regan Heath Wrote:
 
 okibi wrote:
 Firstly, this only works on Windows, which is ok as system() doesn't open a
terminal window on Linux.
 
 The problem is that I'm hitting a batch file. When I set the program to point
to cmd.exe, it will cause a command prompt window to open to run the command,
so back to square one.
What creation flags is it using? CREATE_NO_WINDOW or DETACHED_PROCESS? http://msdn2.microsoft.com/en-us/library/ms684863.aspx Regan
Sep 26 2007
parent reply okibi <okibi ratedo.com> writes:
Apparently it wasn't setup... I glanced over it and thought I saw the
CREATE_NO_WINDOW reference. Anyways, it's there now.

It's still creating the window while running the batch script.

okibi Wrote:

 I take that back, CREATE_NO_WINDOW fails (undefined identifier) and
DETACHED_PROCESS works, but the window still opens.
 
 okibi Wrote:
 
 Sorry, I'm not all too familiar with CreateProcess functions.
 
 From what I can tell, it's doing a CREATE_NEW_CONSOLE. Changing it to
CREATE_NO_WINDOW or DETACHED_PROCESS doesn't work.
 
 Regan Heath Wrote:
 
 okibi wrote:
 Firstly, this only works on Windows, which is ok as system() doesn't open a
terminal window on Linux.
 
 The problem is that I'm hitting a batch file. When I set the program to point
to cmd.exe, it will cause a command prompt window to open to run the command,
so back to square one.
What creation flags is it using? CREATE_NO_WINDOW or DETACHED_PROCESS? http://msdn2.microsoft.com/en-us/library/ms684863.aspx Regan
Sep 26 2007
parent reply Regan Heath <regan netmail.co.nz> writes:
okibi wrote:
 Apparently it wasn't setup... I glanced over it and thought I saw the
CREATE_NO_WINDOW reference. Anyways, it's there now.
 
 It's still creating the window while running the batch script.
It's working for me with either CREATE_NO_WINDOW or DETACHED_PROCESS or both. Attached is the source (mofified to work with D 2.0). Note that I defined: const CREATE_NO_WINDOW = 0x08000000; in windows.d. Compile with "dmd createprocess windows test" then run "createprocess.exe". Regan
Sep 26 2007
parent reply okibi <okibi ratedo.com> writes:
Well, I was going by what clay had said regarding setting the program to
CMD.exe and the arguments to the batch script. Simply hitting the batch script
works fine, apparently.

Thanks for all your help!

Regan Heath Wrote:

 okibi wrote:
 Apparently it wasn't setup... I glanced over it and thought I saw the
CREATE_NO_WINDOW reference. Anyways, it's there now.
 
 It's still creating the window while running the batch script.
It's working for me with either CREATE_NO_WINDOW or DETACHED_PROCESS or both. Attached is the source (mofified to work with D 2.0). Note that I defined: const CREATE_NO_WINDOW = 0x08000000; in windows.d. Compile with "dmd createprocess windows test" then run "createprocess.exe". Regan
Sep 26 2007
parent Regan Heath <regan netmail.co.nz> writes:
okibi wrote:
 Well, I was going by what clay had said regarding setting the program to
CMD.exe and the arguments to the batch script. Simply hitting the batch script
works fine, apparently.
 
 Thanks for all your help!
My code is "setting the program to cmd.exe", eg. execProcess(`c:\windows\system32\cmd.exe`,`test.bat`) Regan
Sep 26 2007