[SOLVED] How to use command xargs to run my custom program?
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
The problem is not with xargs, but with your program. xrags gives the output of ls to your program, but the program prints out only the first two arguments argv[0] and argv[1].
You can look at the xargs man page to find how to set the max number of arguments to dump on every iteration of the command. However what you should do is to modify your program to iterate through all the given arguments, in my opinion.
I also don't like using ls like that, it will give you trouble some day.
If you insist on working on the files one by one, why not just build a list of files using your friendly neighbourhood shell (which I assume to be Bash here; for other shells, see their documentation) and then loop on that list:
Code:
for i in *; do ./a.out "$i"; done
which is what you originally thought xargs would have done, if I understood you correctly (but still, do modify your program to handle multiple arguments, if it is suitable).
Edit: ha, now that I read the linked page in post #4, I noticed that the for loop was mentioned there as an option to ls Great.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.