代码之家  ›  专栏  ›  技术社区  ›  Pietro

如何从介子脚本运行shell命令?

  •  2
  • Pietro  · 技术社区  · 6 年前

    如何运行shell命令(例如。 cp ,即复制)从介子构建脚本?

    我试过这个代码:

    r = run_command('cp', 'test.txt', 'test2.txt')
    
    if r.returncode() != 0
      warning('Command failed')
    endif
    

    但它什么也没做。
    run_command 运行成功(返回0),但未复制文件。
    内容提供商 具有 cp3 ,我从介子得到一个错误消息,进程终止,它甚至没有到达下一行。
    如果我替换 test.txt test0.txt ,我从脚本中得到一条错误消息。

    运行\u命令


    参考文献: https://mesonbuild.com/External-commands.html

    1 回复  |  直到 6 年前
        1
  •  3
  •   pmod    6 年前

    unspecified 目录,因此,请尝试指定完整的文件名,例如:

    source = join_paths(meson.source_root(), 'test.txt')
    dest = join_paths(meson.build_root(), 'test2.txt')
    message('copying @0@ to @1@ ...'.format(source, dest))
    r = run_command('cp', source, dest)