Last active
March 12, 2016 21:44
-
-
Save omerfeyyaz/fb50eb0dc772d437350a to your computer and use it in GitHub Desktop.
Shell komutlarını çalıştırmak
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String executeShellCommand(String command) { | |
StringBuilder stringBuilder = new StringBuilder(); | |
Process process = null; | |
BufferedReader br = null; | |
try { | |
process = Runtime.getRuntime().exec(command); | |
br = new BufferedReader(new InputStreamReader(process.getInputStream())); | |
String line; | |
while ((line = br.readLine()) != null) { | |
stringBuilder.append(line + "\n"); | |
} | |
process.waitFor(); | |
} catch (IOException | InterruptedException e) { | |
e.printStackTrace(); | |
} finally { | |
try { | |
if (process != null) process.destroy(); | |
if (br != null) br.close(); | |
} catch (Exception exception) { | |
exception.printStackTrace(); | |
} | |
} | |
return stringBuilder.toString(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main (int argc, char *argv[]) | |
{ | |
system("notepad"); | |
cin.get(); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QtCore/qcoreapplication.h> | |
#include <QtCore/qprocess.h> | |
#include <iostream> | |
int main(int argc, char **argv) { | |
QProcess process; | |
process.start("ls -la"); | |
process.waitForFinished(-1); | |
QString stdOut = process.readAllStandardOutput(); | |
QString stdErr = process.readAllStandardError(); | |
std::cout << stdOut.toStdString() << std::endl; | |
std::cout << stdErr.toStdString() << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment