Permalink
Browse files

use tango process and io redirects

  • Loading branch information...
1 parent c9c101e commit 87ed26bf8ba787e9c8860e02612f50c941e40d06 @wolfwood wolfwood committed Oct 24, 2010
Showing with 40 additions and 19 deletions.
  1. +40 −19 util/soundclip.d
View
@@ -4,64 +4,85 @@ import tango.stdc.posix.unistd;
import tango.stdc.posix.signal;
import tango.stdc.stringz;
import tango.std.posix.stdlib;
+tango.sys.Process;
class SoundClip{
private:
char[] exe;
char[] filename;
- pid_t pid;
+ //pid_t pid;
bool paused;
+ Process p;
+
public:
this(char[] fn){
exe = "cvlc";
filename = fn;
- pid = 0;
}
bool start(){
- if(pid != 0){return false;}
+ if(p !is null){return false;}
- if((pid = fork()) == 0){
- char[] temp = exe ~ filename;
-
- execlp(toStringz(exe), toStringz(exe), toStringz(filename), cast(void*)null);
+ //if((pid = fork()) == 0){
+ char[] temp = exe ~ filename;
+
+ try{
+ p = new Process (temp, null);
+ p.copyEnv(true);
+
+ p.setRedirect(7);
+
+ p.execute;
+ }
+ catch (ProcessException e)
+ Stdout.formatln ("Process execution failed: {}", e);
- }else{
+ //execlp(toStringz(exe), toStringz(exe), toStringz(filename), cast(void*)null);
+
+ //}else{
// ???
- if(pid > 0){
+ //if(pid > 0){
- return true;
- }else{
- return false;
- }
- }
+ // return true;
+ //}else{
+ // return false;
+ //}
+ //}
}
bool stop(){
- if(pid == 0){return false;}
+ if(p is null){return false;}
- if(kill(pid, SIGKILL) != 0){return false;}
+ //if(kill(pid, SIGKILL) != 0){return false;}
//XXX: wait for child zombie
+ p.kill();
+
+ //auto result = p.wait;
+
+ //Stdout.formatln ("Process '{}' ({}) exited with reason {}, status {}",
+ // p.programName, p.pid, cast(int) result.reason, result.status);
+
+
return true;
}
bool pause(){
- if(pid == 0 || paused){return false;}
+ if(p !is null || paused){return false;}
return signal(SIGSTOP);
}
bool unpause(){
- if((pid == 0) || !paused){return false;}
+ if((p !is null) || !paused){return false;}
return signal(SIGCONT);
}
bool signal(int sig){
- return (kill(pid, sig) == 0);
+ return (kill(p.pid, sig) == 0);
}
}

0 comments on commit 87ed26b

Please sign in to comment.