简体   繁体   English

如何将包装脚本附加到二进制文件?

[英]How do I attach a wrapper script to a binary?

I have an executable say a.out. 我有一个可执行文件说a.out。 What I want to do is to attach a wrapper script to this executable which does a few things and then calls a.out. 我要做的是将包装脚本附加到此可执行文件,该脚本执行一些操作,然后调用a.out。 However, I would like to just have one file which I can distribute instead of two files. 但是,我只想分配一个文件而不是两个文件。 Any suggestions on how to do this? 有关如何执行此操作的任何建议?

I'm not terribly concerned about portability. 我并不十分担心可移植性。 Any solution that uses bash, perl or python is preferred but any scripting language would do. 首选使用bash,perl或python的解决方案,但任何脚本语言都可以。

#!/bin/bash

echo "Do few things before calling a.out"
/path/to/a.out 
echo "Done calling a.out"

您可以将a.out追加到包装脚本中(在bash中exit或在Perl中exit __END__之后),这会将其从自身提取到新文件中,更改其权限并运行它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM