TOPIC: Spawn process help
#1040
Spawn process help 2 Years, 10 Months ago
Hi

Just a couple,
1) How do I determine the current working directory in suneido ? Dir() returns the contents of the current directory but no full path ?
2) Tried to spawn this process
Code:

Spawn(P.NOWAIT, "cdrtoolscdrecord.exe", " -eject dev=0,0,0 "')


However this
Code:

System("cdrtoolscdrecord.exe dev=0,0,0 -eject"')

Works perfectly !?!
The error I get is "Badly placed option. Global options must be before any track". So it appears that the executable is found and the necessary DLL's got loaded.
3) (Assuming item 2 can be resolved) when a process is spawned using the P.DETACH is there a way of capturing the process output that normally would have gone to the console ?

thx
z
 
 
#1041
Re:Spawn process help 2 Years, 10 Months ago
1) You can get the current directory with GetCurrentDirectory()

2) System uses the command shell (e.g. cmd.exe) so there are differences from Spawn. I don't know if it's significant that you had the arguments reversed in the two cases, that's maybe just a typo on the forum.

To get even finer control you can use CreateProcess directly.

To capture the output you could redirect it to a file, but then you'd have to use System since Spawn doesn't support redirection. You could also use the new RunPiped but that's not really running detached, although the pipe's buffering does allow some overlap.

Suneido simply calls _spawnlp so I'm not sure why it isn't working. Suneido passes the command as arg 0 since that is what most programs expect. But if arg 0 had a forward slash it might get interpreted as the command followed by a slash option.
 
 
andrew
 
#1042
Re:Spawn process help 2 Years, 10 Months ago
Thanks andrew
Looks like the issue is the multiple arguments
Code:

intptr_t _spawnlp(
   int mode,
   const char *cmdname,
   const char *arg0,
   const char *arg1,
   ... const char *argn,
   NULL 
);


However the implementation (builtin.cpp)

Code:

Value su_spawn()
{
const int nargs = 3;
return spawnlp(ARG(0).integer(), 
ARG(1).str(), ARG(1).str(), ARG(2).str(), NULL);
}
PRIM(su_spawn, "Spawn(mode, command, args)"');



Only allows one argument to be passed (If I am reading it correctly)
Maybe this could be enhanced to be an array ? (Wish I had a proper build environment setup)

Anyways Ill try the CreateProcess thingy..

Thx again
Steve
 
 
#1043
Re:Spawn process help 2 Years, 10 Months ago
Booyah
create process seems to do the trick
Here is the dirty little code sample
Code:


result=Object(nLength:0 ,
 lpSecurityDescriptor:0,
 bInheritHandle:true
 );
startup = Object(cb:0,
lpReserved:0,
lpDesktop:0,
lpTitle:'ss',
dwX:0,
dwY:0,
dwXSize:100,
dwYSize:410,
dwXCountChars:0,
dwYCountChars:0,
dwFillAttribute:0,
dwFlags:0,
wShowWindow:1,
cbReserved2:0,
lpReserved2:'',
hStdInput:0,
hStdOutput:1,
hStdError:1

)
processinformation = Object(
hProcess:0
hThread:0
dwProcessId:0
dwThreadId:0
)
// r = Spawn(P.NOWAIT, "cdrtoolscdrecord.exe", "dev 0,0,0" )
r = CreateProcess(NULL, "cdrtoolscdrecord.exe dev=0,0,0 -load", result, result,
true,0,0,"G:prjsuneidoSuneido Burner",
startup,processinformation)
Print(r)

}

 
 
#1044
Re:Spawn process help 2 Years, 10 Months ago
Hmmmm. Programs usually just receive a single command line string and split it up into arguments themselves. I assumed that spawnlp would simply combine the arguments into one command line string and that therefore it would not matter if I passed everything into arg1.

For example:

Spawn(P.WAIT, 'cp', 'version.txt version.tmp')

seems to work ok despite two arguments being passed together. Maybe it depends on the individual program.

It wouldn't be hard to make Spawn take multiple arguments and pass them on. Would just have to switch to spawnvp to pass an argument array.
 
 
andrew