C++ Code Playground - system() Return Value | Sololearn: Learn to code for FREE!
+ 7

C++ Code Playground - system() Return Value

I tried using system() in <cstdlib>/<stdlib.h> to interact with the shell which runs on SL server-side. No matter what I do, system() returns -1. It looks like SL blocked system() calls on purpose (which rationale I definitely understand). I was just wondering if anybody tried this in the past, and if my assumptions on access restrictions are correct. The following code displays 0 on my local machine, but -1 on SL. #include <iostream> #include <cstdlib> int main() { std::cout << system(""); }

31st Aug 2019, 2:39 AM
Fermi
Fermi - avatar
4 ответов
+ 9
"If we pass null pointer in place of string for command parameter, system returns nonzero if command processor exists (or system can run). Otherwise returns 0" https://code.sololearn.com/cNjLK8m9flal/?ref=app https://en.m.wikibooks.org/wiki/C%2B%2B_Programming/Code/Standard_C_Library/Functions/system
31st Aug 2019, 2:56 AM
jay
jay - avatar
+ 4
Thanks, Jay. Tsk, I really hope it was just me doing something wrong. Much would be achievable if we are provided with even limited access to the file system (like in Termux).
31st Aug 2019, 3:34 AM
Fermi
Fermi - avatar
0
Sandy Taylor Please avoid writing irrelevant response in someone's thread answer section. If you have a question then you can make your own thread where you can speak your doubt. Mind still to try to stay on topic and follow forum general guides. See the FAQ page for common answers to questions - and tips for authoring a thread in the forum. Hoping you a great SoloLearn journey 👍 https://www.sololearn.com/faq https://www.sololearn.com/Discuss/333866/?ref=app
7th Sep 2019, 4:14 AM
Ipang
- 1
I do not know how to code I want to learn where do I start any help?
1st Sep 2019, 9:27 PM
Sandy Taylor