Hello All!

I have a program in C# and I am trying to write it in C++.
Somewhere in my app I have to run a command. In C++ I am trying to do it using system()

To run the command I have to give the absolute path. For example:

system("\"C:\\Documents and Settings\\myUser\\myProject\\app.exe\" -vb \"C:\\Documents and Settings\\myUser\\file.txt\"");

So, I am trying to run the exe called app.exe and it requires a file as parameter that I call using -vb. If I enter that command through the console, it works properly. But through the system() method it´s not working. The error says: 'C:\Documents' is not a command. If I use 'cout' to see exactly what is being sent, I get:

"C:\Documents and Settings\myUser\myProject\app.exe" -vb "C:\Documents and Settings\myUser\file.txt"

and If I type it through the console it works perfectly.

I also tried

"C:\Documents and Settings\myUser\myProject"\app.exe -vb "C:\Documents and Settings\myUser\file.txt" and other variations.


The problem is that I put "" between the path to the app.exe.
This command also works in C#. But there I use ProcessStarInfo.

I hope someone helps me.
Thx a lot.

system("\"C:\\Documents and Settings\\myUser\\myProject\\app.exe\" -vb \"C:\\Documents and Settings\\myUser\\file.txt\"");
it should be
system("C:\\Documents and Settings\\myUser\\myProject\\app.exe -vb \"C:\\Documents and Settings\\myUser\\file.txt""

system("\"C:\\Documents and Settings\\myUser\\myProject\\app.exe\" -vb \"C:\\Documents and Settings\\myUser\\file.txt\"");
it should be
system("C:\\Documents and Settings\\myUser\\myProject\\app.exe -vb \"C:\\Documents and Settings\\myUser\\file.txt""

You meant

system("C:\\Documents and Settings\\myUser\\myProject\\app.exe -vb \"C:\\Documents and Settings\\myUser\\file.txt\"" ? (forgot the \ before the last " )

It doesnt work either =( I had already tried it and I tried it again.
I get the same 'C:\Documents' is not an internal command

Any other ideas?

Well, I would suggest you to move the app.exe to the same folder in which you save your .cpp files. Then you can just use type: system ("app.exe -vb \C:\\Documents and Settings\\myUser\\file.txt\"); I'm not sure about the -vb command because i havent use it before.

system("\"C:\\Documents and Settings\\myUser\\myProject\\app.exe\" -vb \"C:\\Documents and Settings\\myUser\\file.txt\"");

Try this one ..

system("\"\"C:\\Documents and Settings\\myUser\\myProject\\app.exe\" -vb \"C:\\Documents and Settings\\myUser\\file.txt\"\"");

I´ve tried that either. It adds ""C:\Documents and......\file.txt"". Then it does not work.

Anyway, thx a lot for helping. I will keep trying. Maybe another command could solve it. As soon as I solve it I will post here.

See you!

Hello!

I found another way of doing that. It was using ShellExecuteEx.
It allowed me to enter the application´s path and then the parameters.

SHELLEXECUTEINFO SHInfo = {0};

        SHInfo.cbSize = sizeof (SHELLEXECUTEINFO);
        SHInfo.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;
        SHInfo.lpVerb = _T ("open");
        SHInfo.lpFile = _T ("C:\\Documents and Settings\\myUser\\myProject\\app.exe");
        SHInfo.lpParameters = _T (-vb \"C:\\Documents and Settings\\myUser\\file.txt\"");
        SHInfo.nShow = SW_SHOW;

Thx a lot, see you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.