sacredfaith
July 15th, 2010, 05:50 PM
Howdy,
Thank you for all who clicked and are reading...
Quick Stats:
OS: Ubuntu 10.04
g++ --version: g++ (Ubuntu 4.4.3-4ubuntu5) 4.4.3
I am currently trying to get system() to work with a char array. The string is:
"dd if=/dev/random of=scanthis.txt conv=notrunc bs=1M count=2"
#include<iostream>
#include<fstream>
#include<time.h>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#include<unistd.h>
#include<fcntl.h>
#include<sys/stat.h>
#include<sys/types.h>
using namespace std;
int main(){
char command[64]="dd if=/dev/random of=scanthis.txt conv=notrunc bs=1M count=2";
cout << "Starting..." << endl;
system("command");
cout << command << endl;
cout << "File Creation Complete!" << endl;
return 0;
}
Code compiles and runs but does not create scanthis.txt.
Debugging so far I've found that:
when I insert the command in terminal it DOES create scanthis.txt
when I insert a simple shell command 'ls' like this: system("ls"), the ls command works (which means I'm using the system() syntax correctly (I think)).
As you might be able to guess from the crazy number of included files, this is the problem-part of a larger program.
Warm Regards,
sf
Thank you for all who clicked and are reading...
Quick Stats:
OS: Ubuntu 10.04
g++ --version: g++ (Ubuntu 4.4.3-4ubuntu5) 4.4.3
I am currently trying to get system() to work with a char array. The string is:
"dd if=/dev/random of=scanthis.txt conv=notrunc bs=1M count=2"
#include<iostream>
#include<fstream>
#include<time.h>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#include<unistd.h>
#include<fcntl.h>
#include<sys/stat.h>
#include<sys/types.h>
using namespace std;
int main(){
char command[64]="dd if=/dev/random of=scanthis.txt conv=notrunc bs=1M count=2";
cout << "Starting..." << endl;
system("command");
cout << command << endl;
cout << "File Creation Complete!" << endl;
return 0;
}
Code compiles and runs but does not create scanthis.txt.
Debugging so far I've found that:
when I insert the command in terminal it DOES create scanthis.txt
when I insert a simple shell command 'ls' like this: system("ls"), the ls command works (which means I'm using the system() syntax correctly (I think)).
As you might be able to guess from the crazy number of included files, this is the problem-part of a larger program.
Warm Regards,
sf