首页 文章

通过命令行将文件名作为字符串传递到Maple中

提问于
浏览
1

我正在尝试使用命令行界面在外部程序中使用Maple函数 . 函数数据将通过文件传递 . 为了演示该问题,我创建了两个文件:/home/user_name/test.mpl和/home/user_name/test_data.txt .

test.mpl(“cat”演示了Maple函数的使用):

#filename := "/home/user_name/test_data.txt":
print(filename):

i := parse(readline(filename)):
poly := parse(readline(filename)):
s := parse(readline(filename)):

print(cat(convert(poly+i,string), " ", s)):

test_data.txt:

1
x^2 * y + 1
"A string."

根据manual,我可以使用这样的东西(但这个例子不包括两个文件的使用,一个作为代码,另一个作为参数):

/usr/local/maple/bin/maple -c 'datafile:="/tmp/12345.data";' -c N:=1;

当我尝试

/path/to/maple -c 'filename:="/home/user_name/test_data.txt":' -q /home/user_name/test.mpl

我收到以下错误:

Error, incorrect syntax in parse: `/` unexpected (near 11th character of parsed string)

如果我在文件名字符串中删除第一个 / ,我得到以下输出(在与 readline 相关的错误之前):

/        home       \
|-------------------| . txt
\user_name test_data/

它清楚地表明文件路径不会被解析为字符串(但可能是某种表达式) . 可能我应该使用一些转义序列,对于Maple或shell,但我没有尝试过 .

如果我在test.mpl中获取文件名(取消注释第一行并删除 -c 参数),它可以工作,但这不是我需要的 .

如何通过命令行将文件名作为字符串传递(可能不使用 -c )?

1 回答

  • 1

    它适用于我在Linux上使用命令行Maple,比方说,

    /path/to/maple -c 'filename:=\"/home/user_name/test_data.txt\":' -q /home/user_name/test.mpl
    

相关问题