Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Working with a binary file stored in .app container?


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 2 - Last Post: May 10, 2017 3:43 AM Last Post By: Oleg Merkuriev Threads: [ Previous | Next ]
Oleg Merkuriev

Posts: 9
Registered: 12/27/16
Working with a binary file stored in .app container?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 2, 2017 10:51 AM
I have a binary file inside, say, MyApp.app container. It's a binary called unar to unpack rar files. It perfectly works with a manual command line. Now I'd like MyApp.app to launch unar and the first method I used is sending command line right inside .app container, like this:

ExeDir=ExtractFilePath(GetModuleName(HInstance));// a folder where MyApp.app is placed
NameFile_unrar_dll=ExeDir+"unar"; // referring to unar binary by MyApp.app path
buffer=NameFile_unrar_dll+" "NameSaveFileAll[i]" -D -o "+DirSaveFile; // forming of a command line for extracting a rar file
retrn=system(buffer.c_str()); // launching a command line

And I'm getting this alert: https://image.ibb.co/iczut5/error1.jpg

I thought maybe Mac OS didn't allow to launch a binray from inside the .app container. So decided to just to extract unar from the container to any custom folder, like this:

buffer="cp \""ExeDir"unar \" "+"\""DirSaveFile"\""; // forming of a command line to copy unar binary to DirSaveFile custom folder
retrn=system(buffer.c_str()); // launching a command line

Another error alert was returned: https://image.ibb.co/jXx3mQ/error2.jpg

Any suggestions how can I reach unar binary? Is there a mistake in either method?

Edited by: Oleg Merkuriev on May 2, 2017 10:52 AM
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Working with a binary file stored in .app container? [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 2, 2017 11:24 AM   in response to: Oleg Merkuriev in response to: Oleg Merkuriev
Oleg wrote:

buffer=NameFile_unrar_dll+" "NameSaveFileAll[i]" -D -o
"+DirSaveFile; // forming of a command line for extracting a rar file

retrn=system(buffer.c_str()); // launching a command line

And I'm getting this alert: https://image.ibb.co/iczut5/error1.jpg

The path to the app has spaces in it, so you need to wrap it in quotes.
You should do the same with the other paths, too:

buffer = _D("\"") + NameFile_unrar_dll + _D("\" \"") + NameSaveFileAll[i] 
+ _D("\" -D -o \"") + DirSaveFile + _D("\"");


Or better, use AnsiQuotedStr() instead:

buffer = AnsiQuotedStr(NameFile_unrar_dll, _D('\"')) + _D(" ") + AnsiQuotedStr(NameSaveFileAll[i], 
_D('\"')) + _D(" -D -o ") + AnsiQuotedStr(DirSaveFile, _D('\"'));


I thought maybe Mac OS didn't allow to launch a binray from inside the
.app container. So decided to just to extract unar from the container
to any custom folder, like this:

buffer="cp \""ExeDir"unar \" "+"\""DirSaveFile"\""; // forming of
a command line to copy unar binary to DirSaveFile custom folder
retrn=system(buffer.c_str()); // launching a command line

Another error alert was returned:
https://image.ibb.co/jXx3mQ/error2.jpg

You are placing an extra space between "unar" and the closing quote, thus
making the space part of the path, even though it really is not. So again,
you can use AnsiQuotedStr() instead:

buffer = _D("cp ") + AnsiQuotedStr(ExeDir+"unar", _D('\"') + _D(" ") + AnsiQuotedStr(DirSaveFile, 
_D('\"'));


--
Remy Lebeau (TeamB)
Oleg Merkuriev

Posts: 9
Registered: 12/27/16
Re: Working with a binary file stored in .app container? [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 10, 2017 3:41 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Thanks Remy!

I manage to copy the binary file from the .app container to the destination folder placing ti along with rar files. But as I form next command line to unpack them suing that binary, I got the error message, BUT(!) as I copy and paste this command line from a debug window I created - to the Terminal - it works. Check the picture: https://image.ibb.co/iK6SGQ/18379058_1318920241495960_99750204_o.png - my debug alert message is above and Terminal window with successful command is below.

I suspect there might be another syntax error.... No?

Edited by: Oleg Merkuriev on May 10, 2017 3:41 AM
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02