0
我不肯定还是关于这个问题的措辞,反正 -捕捉“标准输入重定向的文件位置字符串”在C
我已经产生了一些值作为命令行参数,也可执行需要一个文件从标准是这样的:
[email protected]:~$./executable 0.12345 0.12345 < some/directory/somefile.txt
现在有没有什么方法可以让我抓住里面的代码文件位置some/directory/somefile.txt
?
我可以做的是修改代码以将文件位置作为另一个命令行参数,但在这种情况下,我需要更改很多内容。
因此,它会更好,如果我可以做这样的事情 -
int main(int argc, char **argv)
{
char cmd_prompt[80];
char file_location[80];
grab_command_prompt(cmd_prompt);
split_and_grab_last_token(cmd_prompt, file_location);
/* this line below should print: "some/directory/somefile.txt" */
printf("%s\n", file_location);
}
这可能吗?