简体   繁体   English

C程序文本文件中的命令行参数(字符串)

[英]Command Line Arguments (Strings) from textfile for C-Program

I have ac programm, which needs two arguments (strings). 我有一个交流程序,需要两个参数(字符串)。 My problem is I need to do an overflow and one argument needs to be 66000 chars long. 我的问题是我需要执行溢出操作,并且一个参数的长度必须为66000个字符。

So I have a textfile which contains a 66000 chars long string. 所以我有一个包含66000个字符长字符串的文本文件。 But how do I pass this string from the file do the c program as an argument? 但是,如何将文件中的此字符串传递给c程序作为参数呢?

I already tried: myprog < textFile 我已经尝试过:myprog <textFile

But this does not work 但这不起作用

OS: Ubuntu. 操作系统:Ubuntu。

This is more of a bash question. 这更像是一个bash问题。

If you call: 如果您致电:

myprog < textFile

you don't pass textFile as argument, so your c program won't find any argument in char *argv[] . 您没有将textFile作为参数传递,因此您的c程序在char *argv[]找不到任何参数。 Instead STDIN is taken to come from textFile . 取而代之的是STDIN来自textFile Of course you could just read the file content from there, but I understand, you exactly want to pass it as one argument. 当然,您可以从那里读取文件内容,但是我知道,您确实想将其作为一个参数传递。

So you would call: 所以你会打电话给:

myprog "$(cat textFile)"

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

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