Deutsch English Français Italiano |
<vbv04v$aci0$1@raubtier-asyl.eternal-september.org> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!news.nobody.at!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail From: Bonita Montero <Bonita.Montero@gmail.com> Newsgroups: comp.lang.c Subject: Re: Command line globber/tokenizer library for C? Date: Thu, 12 Sep 2024 17:08:24 +0200 Organization: A noiseless patient Spider Lines: 33 Message-ID: <vbv04v$aci0$1@raubtier-asyl.eternal-september.org> References: <lkbjchFebk9U1@mid.individual.net> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 12 Sep 2024 17:08:15 +0200 (CEST) Injection-Info: raubtier-asyl.eternal-september.org; posting-host="b5c2e06992f5c2dd6f467c961945a11e"; logging-data="340544"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18rSqiVG0nQkQd8l2qpBUGaiHDkwCiD7/4=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:POP/DQOJ+jYhtjNDDcSJDgbvVnM= Content-Language: de-DE In-Reply-To: <lkbjchFebk9U1@mid.individual.net> Bytes: 2067 Am 10.09.2024 um 21:01 schrieb Ted Nolan <tednolan>: > I have the case where my C program is handed a string which is basically > a command line. I tried to experiment with that with /proc/<pid>/cmdline. The first problem was that the arguments aren't space delimited, but broken up with zeroes. The second problem was the cmdline-file doesn't contain the original commandline but with expanded files. This was my code so far: #include <iostream> #include <fstream> #include <sstream> #include <algorithm> #include <unistd.h> using namespace std; int main() { pid_t pid = getpid(); string cmdLineFile( (ostringstream() << "/proc/" << pid << "/cmdline").str() ); ifstream ifs; ifs.exceptions( ifstream::failbit | ifstream::badbit ); ifs.open( cmdLineFile ); string fullCmdLine; ifs >> fullCmdLine; ifs.close(); replace( fullCmdLine.begin(), fullCmdLine.end(), (char)0, (char)' ' ); cout << fullCmdLine << endl; }