Find the answer to your Linux question:
Results 1 to 2 of 2
Like Tree1Likes
  • 1 Post By Cabhan
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 ...
  1. #1
    Just 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

  2. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    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().
    wookie1 likes this.
    DISTRO=Arch
    Registered Linux User #388732

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...