小编Chr*_*ris的帖子

将文件夹scp到保持目录布局的远程系统

我有一个包含数百个嵌套子文件夹的大型目录树.我只需要将4个文件夹及其内容复制到远程系统,但我需要将目标文件夹结构保持不变.

例如

./test/sub1/subsub1/hello.txt
./test/sub1/subsub2/hello2.txt    
./test/sub2/hello3.txt
Run Code Online (Sandbox Code Playgroud)

我想将./test/sub1/subsub1/*复制到目标,例如user @ system:〜/ test/sub1/subsub1/*但我不想复制subsub2或sub2.

我尝试过如下使用scp:

scp -r ./test/sub1/subsub1 me@my-system:~/test/sub1/subsub1
Run Code Online (Sandbox Code Playgroud)

结果:scp:/ test/sub1/subsub1:没有这样的文件或目录

我也尝试过:

scp -r ./test/sub1/subsub1 me@my-system:~/test
Run Code Online (Sandbox Code Playgroud)

这可以工作,但会将所有文件转储到一个目录中.不维护/ test/sub1/subsub1目录结构.

如何复制文件夹,同时保持其结构?

linux scp

11
推荐指数
2
解决办法
3万
查看次数

Python3 C++ 模块 - 异常 - 未持有 GIL

我已经创建了我遇到的问题的最小重现,尝试创建基于 C++ 的 Python3 模块。构建环境为CMake、Visual Studio Pro 2019、WinSDK 10.0.18362、Python 3.9.4。执行时:

python3 -c "import pymod"
Run Code Online (Sandbox Code Playgroud)

我将在发布模式下通过 NULL 访问得到异常。在调试 Python 中,我获得了更多信息。

我的 CMakeLists.txt

cmake_minimum_required(VERSION 3.15)

project(pymod_minimal_repo_example)

find_package(Python3 COMPONENTS Interpreter Development)

add_library(pymod SHARED)
target_sources(pymod PRIVATE pymodmodule.cpp)
set_target_properties(pymod PROPERTIES SUFFIX ".pyd")
target_compile_options(pymod PRIVATE /Zi)
target_link_options(pymod PRIVATE /DEBUG:FULL)
target_link_libraries(pymod PRIVATE ${Python3_LIBRARIES})
target_include_directories(pymod PRIVATE ${Python3_INCLUDE_DIRS})
Run Code Online (Sandbox Code Playgroud)

按照此 python 参考:https://docs.python.org/3.9/extending/extending.html#a-simple-example我创建了以下内容:

#define PY_SSIZE_T_CLEAN
#include <Python.h>

static struct PyModuleDef pymodmodule = {
    PyModuleDef_HEAD_INIT, // m_base
    "pymod",               // m_name
    NULL,                  // m_doc
    -1,                    // m_size - submod not support …
Run Code Online (Sandbox Code Playgroud)

c++ windows module cmake python-3.x

5
推荐指数
1
解决办法
1349
查看次数

从std :: stringstream传递std :: string引用作为参数

我使用std :: stringstream构造一个字符串,然后尝试将完成的字符串作为对函数的引用传递给一个函数,该函数将std :: string&作为参数.

我在GCC上收到编译错误:

../src/so.cpp:22:21: error: invalid initialization of non-const reference of type ‘std::string& {aka std::basic_string<char>&}’ from an rvalue of type ‘std::basic_stringstream<char>::__string_type {aka std::basic_string<char>}’
../src/so.cpp:12:6: error: in passing argument 1 of ‘void myFunc(std::string&)’
make: *** [src/so.o] Error 1
Run Code Online (Sandbox Code Playgroud)

在Windows VS2012上编译相同的代码,但在我的Linux和Android版本上失败.这是什么原因?

我可以通过暂时将ss.str()分配给临时的std :: string然后通过引用传递该字符串来解决这个问题,但这看起来有些愚蠢.干净利落的正确方法是什么?

#include <iostream>
#include <sstream>

void myFunc (std::string& msg)
{
    std::cout << msg << std::endl;
}

int main (void)
{
    std::stringstream ss;
    ss << "this is a test";

    myFunc (ss.str());              // Fails

    std::string s = ss.str(); …
Run Code Online (Sandbox Code Playgroud)

c++ parameters reference

4
推荐指数
1
解决办法
1354
查看次数

标签 统计

c++ ×2

cmake ×1

linux ×1

module ×1

parameters ×1

python-3.x ×1

reference ×1

scp ×1

windows ×1