Skip to content

Instantly share code, notes, and snippets.

@omerfeyyaz
Last active March 12, 2016 21:44
Show Gist options
  • Save omerfeyyaz/fb50eb0dc772d437350a to your computer and use it in GitHub Desktop.
Save omerfeyyaz/fb50eb0dc772d437350a to your computer and use it in GitHub Desktop.
Shell komutlarını çalıştırmak
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();
}
#include <iostream>
using namespace std;
int main (int argc, char *argv[])
{
system("notepad");
cin.get();
return 0;
}
#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