Sarah Mohamed
Sarah Mohamed

Reputation: 33

Access C drive using C++ programming

I have a project that must hide a file into an image , first I used command prompt and it goes well. Now I am trying to apply this commands using C++ programming language, but each time it gives me that system can't find the specified path although it exists and work well using command prompt.

This my code:

system("cd\\"); \\access C
system("cd x"); \\X is name of folder in C
system("copy /b pic.jpg + file.rar NEWPICTURE.jpg");

This is the source of commands: http://www.instructables.com/id/How-to-Hide-Files-Inside-Pictures/

Upvotes: 0

Views: 530

Answers (1)

Ben Voigt
Ben Voigt

Reputation: 283684

Every time you call system(), a new shell process is created to run that single command. When that shell exits, its local context, including working directory and environment variables, is lost. The next call to system() copies the context of the parent process (your program) all over again.

Your options are to pass a command list/pipeline to a single system() call, or to use functions that affect your own process context, such as chdir().

Upvotes: 3

Related Questions