Computing.Net > Forums > Unix > Piping a binary file ONLINE?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Piping a binary file ONLINE?

Reply to Message Icon

Name: dave
Date: August 15, 2003 at 15:57:57 Pacific
OS: Solaris
CPU/Ram: sparc
Comment:

Hi,
I have a command line tool that takes a binary file as an argument and produce a text-based file. (For example % myapp -rt file.bin).

I want to make this tool available online so that the user could run it with their own binary file. My line of thinking is to have a shell script, but then I need to figure out whether to allow the user to upload his file to my webserver and then run it from there or any other efficient way. Or how can I pipe the binary file through the application online?

Any ideas/suggestions would be greatly helpful.

Thanks in advance.



Sponsored Link
Ads by Google

Response Number 1
Name: zeroguy
Date: August 18, 2003 at 21:22:25 Pacific
Reply:

This is not much of a solution, but I thought I'd try to give you *something* to go on...

The only way I can think of to do this would be to use a Java applet (as much as I hate using Java). Applets always resolve paths as if they were on the user's machine (the one who accessed the page with the applet), so you could use the user's file as an argument to the command as a regular path, but the path for the command itself would have to (i think) have to be resolved using a URL object, and stuff like that. I can give you more detailson this, but first tell me if this is what you want...

Of course, there almost certainly are other ways to do this, probably with scripting itself, but the only other way I can think of would be using some network programming in C++ which might be too complicated for what you want here (the java 'solution' is much simpler... if it works)


0

Response Number 2
Name: dave
Date: August 18, 2003 at 23:34:24 Pacific
Reply:

Thanks for the reply. Yes, a Java applet solution should work here as you explained. I do not have any experience with Java. But if you could give me a headstart that would be really great. Thanks a lot!


0

Response Number 3
Name: zeroguy
Date: August 20, 2003 at 18:08:35 Pacific
Reply:

Well, I had never tried doing this before, I was just theorizing, and upon further research I just did, it wouldn't really work in the way I thought. But there may be another way to do it. If you could read the data from the binary file in the applet, then call the tool with the data as an argument.

But this depends on a few things, like how big would the binary file be, approximately? And do you want the resultant file on the server, or the user's machine? A little more details would help.

You can try to learn a little Java in the meantime, if you want. First learn the basics, then some specific stuff to look into for this are the JApplet class (you'll need getDocumentBase(), I think), the URL class, and exec() in the Runtime class.

Also, do you have experience with other languages? (C-like, or anything OOP, really) It would help a great deal if you already knew something else to learn a bit of Java.

And one more thing to say: couldn't the user just quickly download the tool themselves? I know there are portability problems there, of course, but it all depends on more details of this tool.


0

Response Number 4
Name: dave
Date: August 22, 2003 at 10:50:54 Pacific
Reply:

Thanks a lot for your help!

The max size of the binary file (Dump file) could be about 0.5 MByte. This is a packed binary data file.

The output is ascii text written to stdout, and it's rarely more than ~20 KB. We'd really just want to display it, but option to save it on the user's machine as a text file might be useful in some cases.

The tool is a binary. To use it for this application you would pass it some commands on the unix command line. Specifically,suppose FILE is the binary dump the user wants interpreted. To print the desired info to stdout:
% MyApp -x "dumpf load FILE"

There are some configuration issues that prevents us from allowing the user to download the tool.

And, I am familiar with C and C++ and have some knowledge of Java, but NOT Java Applets.

Thanks for your help again. I appreciate it.


0

Response Number 5
Name: zeroguy
Date: September 8, 2003 at 19:21:36 Pacific
Reply:

Alrighty, I have not looked at this problem for some time now, and I don't really remember what I was thinking at the time, becuase it really does not seem possible. If you want to pursue the Java route, I suggest you ask someone much more experience in Java than I, as I have just done a few things with Java applets. You might want to ask someone about resolving URL objects as an exec() parameter or something like that.

But, if I were to do this, I would have the user upload the file via PHP, but .5MB seems like quite a high limit, and may take a long time for users with slower modems to upload it. But, then again, the data is going to have to transferred no matter how you do it, so it may take a long time with any solution. And, when you upload the file via PHP, you don't have to give any more permissions on files around where your tool is, just as long as the 'other' user has executable permissions on the tool itself, of course.

Tell me if you want to go the PHP route, becuase I know exactly how to do it, and I will tell. If you want to go Java, ask someone else, becuase I don't know, it's too late right now, and school started up again and all homework and no play makes zero a cranky bitch.

And with that cheery thought, I bid you adieu


0

Related Posts

See More



Response Number 6
Name: dave
Date: September 9, 2003 at 10:25:01 Pacific
Reply:

Yes, I was thinking about PHP too. In order to g owith Java, I have to figure out how to deal with URL objects and resolving those. So I think I should go with PHP. If you have some time, please let me know some details.

Good luck with school!

Thanks again...


0

Response Number 7
Name: zeroguy
Date: September 9, 2003 at 14:49:15 Pacific
Reply:

File transfers are relatively simple in PHP if you follow php.net, but you have to learn php first, so here's a few things to get you started:

First, you have a page to upload the file (obviously). Somewhere in the page include the following code:

        

        Upload file: 

        

Just don't alter about anything inside the HTML tags and it should work fine. And you should replace the 500000 in 'value="500000"' with whatever the max file size is, in bytes. I just put 500000 in there becuase it seemed close enough, I didn't feel like calculating .5MB in bytes, so change it if you wish.

Next, you have the PHP file (called 'convert.php' in this example), which contains only the following code:

And I believe that would output the output of your tool. This is assuming that your shell script returns 0 on success, and anything else if you don't want to output the results. On the second line of that code, replace 'yourcommand' with your command (with an absolute path if it is not in a path defined in your PATH), and '-flag' with the flags you want to pass to it, and '-flagsafterfile' with the flags that go after the filename, if any.

And I'm not sure if the second to last line is necessary, it just deletes the temporary PHP uploaded file, but I've been told that they go away on their own, but I'm not really sure if that was true.

Tell me if you have any problems, this is reliant on the PHP version of your server, so it might not work. I'll be glad to help.


0

Response Number 8
Name: zeroguy
Date: September 9, 2003 at 14:50:57 Pacific
Reply:

File transfers are relatively simple in PHP if you follow php.net, but you have to learn php first, so here's a few things to get you started:

First, you have a page to upload the file (obviously). Somewhere in the page include the following code:

<form enctype="multipart/form-data" action="convert.php" 
method="POST">

        <input type="hidden" name="MAX_FILE_SIZE" value="500000">

        Upload file: <input name="userfile" type="file">

        <p><input type="submit" value="Convert">

</form>

Just don't alter about anything inside the HTML tags and it should work fine. And you should replace the 500000 in 'value="500000"' with whatever the max file size is, in bytes. I just put 500000 in there becuase it seemed close enough, I didn't feel like calculating .5MB in bytes, so change it if you wish.

Next, you have the PHP file (called 'convert.php' in this example), which contains only the following code:

<?

exec("yourcommand -flag " . $_FILES['userfile']['tmpname'] 
. "-flagsafterfile", $output, $ret);

if($ret != 0) exit("error with tool");

foreach($output as $line)

     echo $line;

system("rm " . $_FILES['userfile']['tmpname']);

?>

And I believe that would output the output of your tool. This is assuming that your shell script returns 0 on success, and anything else if you don't want to output the results. On the second line of that code, replace 'yourcommand' with your command (with an absolute path if it is not in a path defined in your PATH), and '-flag' with the flags you want to pass to it, and '-flagsafterfile' with the flags that go after the filename, if any.

And I'm not sure if the second to last line is necessary, it just deletes the temporary PHP uploaded file, but I've been told that they go away on their own, but I'm not really sure if that was true.

Tell me if you have any problems, this is reliant on the PHP version of your server, so it might not work. I'll be glad to help.


0

Response Number 9
Name: zeroguy
Date: September 9, 2003 at 14:52:21 Pacific
Reply:

Bah, sorry about posting twice. I was trying to get the code converter to work, and it just seems odd to me that the link for it is ONLY provided in the programming section. bah.


0

Response Number 10
Name: Dave
Date: September 10, 2003 at 14:11:27 Pacific
Reply:

Thanks a ton zero! I will get started with your code and advise.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Tailing a rollover file scripting string parsing



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Piping a binary file ONLINE?

text file and a binary file www.computing.net/answers/unix/text-file-and-a-binary-file/2690.html

convert a binary file to ascii www.computing.net/answers/unix/convert-a-binary-file-to-ascii/6213.html

how to read binary files in Unix www.computing.net/answers/unix/how-to-read-binary-files-in-unix/4566.html