-
Notifications
You must be signed in to change notification settings - Fork 757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sclang: introduce unixCmd for array of arguments #1856
sclang: introduce unixCmd for array of arguments #1856
Conversation
|
||
if (!isKindOfSlot(a, class_string)) return errWrongType; | ||
|
||
char *cmdline = (char*)malloc(slotRawObject(a)->size + 1); | ||
err = slotStrVal(a, cmdline, slotRawObject(a)->size + 1); | ||
if(err) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These error checks are not necessary because above the slot was already checked for class_string which is the same check done inside slotStrVal
If the command is not found or the process exits with an error, it throws a primitive failed, right ? Is there anyway to easily get both the stdout and the error code ? See Pipe *call / *callSync |
No. if execve fails error 127 is reported. If the process exits with an error that error is reported (posted). No primitive failed error it thrown.
You can get stdOut via unixCmdGetStdOut which uses Pipe internally. If there is an error the error goes to stderr not stdout, therefore it won't be displayed with unixCmdGetStdOut. You can however redirect stderr to stdout in the shell:
|
Felix - check the unixCmd help: http://doc.sccode.org/Classes/String.html#-unixCmd Arguments: unixCmd is asynchronous, so it can't throw an error in SC if the child process fails. |
std::vector<char> v2( str2.begin(), str2.end() ); | ||
v2.push_back('\0'); | ||
argv[2] = v2.data(); | ||
argv[3] = NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nullptr
is a bit more typesafe than NULL
I don't understand why when I use vector for the argv strings, although they are printed correctly by cout, for instance 'echo' will not print anything. I'm I doing something wrong ?
|
6327573
to
9a7b145
Compare
Except for the unique_ptr I think I addressed the other issues. Also, this doesn't work for windows, so for windows the primitive will just post a message, not sure that is the proper to deal with this. I'm not familiar with the windows process code to do changes there. |
aa52d09
to
ea4641c
Compare
Doesn't build for osx:
What could be the issue ? Perhaps #include was missing. Added that, let's see if it builds. edit: ok, it builds now. |
ea4641c
to
d008339
Compare
sclang: introduce unixCmd for array of arguments
fixes #1738
Incorporated some of @timblechmann 's feedback.
tested with:
["/bin/echo","hello","world"].unixCmd
["/bin/echo",1,"world"].unixCmd
[].unixCmd
x = ["/usr/local/bin/scsynth","-u","57128"].unixCmd
pid at x checks out with pgrep.