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 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: References: 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: Bytes: 2067 Am 10.09.2024 um 21:01 schrieb Ted Nolan : > 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//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 #include #include #include #include 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; }