Results 1 to 2 of 2
Hi I have a problem where I'm trying to run a .exe from c++ using system, the problem is that the argument, a text file, is asked for after calling ...
- 02-08-2012 #1Just Joined!
- Join Date
- Feb 2012
- Posts
- 1
.exe asks for argument
Hi I have a problem where I'm trying to run a .exe from c++ using system, the problem is that the argument, a text file, is asked for after calling the .exe. I need a way to provide this argument.
To clarify in bash I can do this:
cd /programlocation
wine program.exe
This then outputs, Enter input file name :
If i now type
filename.txt
It works, however I cannot figure a way to combine this last step so I can run it using system from c++.
ie
This doesn't work;
std::string location = "cd /blah/"
std::string program = "name"
std::string input = "inputfile.txt";
std::string command = location+"&&"+program+";"+input;
const char *cmd = command.c_str();
system(cmd);
This just asks for input file in the console.
I'm really stuck here so any help is massively appreciated.
Cheers
- 02-10-2012 #2
The program is probably meant to run interactively, which makes it annoying to execute from other programs. If you could specify all of the inputs on the commandline (e.g. "./a.out inputfile.txt"), it would be much easier.
You can do this by redirecting the stdin of the program that you're executing. It looks like you're doing this on Windows though, and I don't have any idea of how to do it on Windows. In Linux you could do it using popen(), which is essentially a shortcut for pipe()/fork()/dup2()/exec().DISTRO=Arch
Registered Linux User #388732


1Likes
