maxscript 获取正在运行的其他软件的路径
时间: 2024-02-04 19:01:05 浏览: 40
在Maxscript中,我们可以使用`dotNet`来获取正在运行的其他软件的路径。具体步骤如下:
首先,我们需要使用`dotnetclass`函数来加载System.Diagnostics命名空间下的`Process`类。代码如下:
```
dotnet.loadAssembly "System.Diagnostics"
processClass = dotNetClass "System.Diagnostics.Process"
```
然后,我们可以使用`processClass`的`GetProcesses`方法获取正在运行的所有进程。代码如下:
```
allProcesses = processClass.GetProcesses()
```
接下来,我们可以遍历`allProcesses`列表,并使用`Process`的`MainModule`属性来获取每个进程的主模块路径。代码如下:
```
for i = 1 to allProcesses.count do
(
mainModulePath = allProcesses[i].MainModule.FileName
print mainModulePath
)
```
最后,我们可以根据需求进一步处理输出的路径信息,例如筛选特定软件的路径等。
以上是使用Maxscript获取正在运行的其他软件的路径的方法。值得注意的是,某些进程由于系统权限限制,可能无法获取其路径或者可能产生异常。因此,建议在使用时加上异常处理机制来处理这些特殊情况。
相关问题
nodejs cmd运行参数
Node.js 的命令行运行参数可以在运行脚本时通过命令行传递。下面是一些常见的 Node.js 命令行参数:
1. 脚本文件:使用 `node` 命令后面跟随要运行的脚本文件的路径,例如 `node script.js`。
2. 选项参数:使用 `--` 或 `-` 开头的参数,用于配置 Node.js 运行环境。例如:
- `--inspect`:启用调试模式,可以通过 Chrome DevTools 进行调试。
- `--max-old-space-size=<size>`:设置最大堆内存大小,例如 `--max-old-space-size=4096` 表示设置最大堆内存为 4GB。
- `-r` 或 `--require`:在脚本运行之前引入指定的模块,例如 `-r esm` 表示在运行脚本前引入 esm 模块。
3. 命令行参数:在运行脚本时可以传递自定义参数,可以在脚本中通过 `process.argv` 获取这些参数。例如:
- `node script.js arg1 arg2`:在脚本中可以通过 `process.argv[2]` 获取 `arg1`,通过 `process.argv[3]` 获取 `arg2`。
这些是一些常见的 Node.js 命令行运行参数,你可以根据需要自定义使用。
提供一个c++端用libtorch和Torch TensorRT加速推理torchscript模型的案例并注释
以下是一个使用libtorch和Torch TensorRT加速推理torchscript模型的C++案例:
```c++
#include <torch/script.h>
#include <iostream>
#include <memory>
#include <chrono>
#include <NvInfer.h>
#include <NvInferRuntimeCommon.h>
#include <NvInferPlugin.h>
#include <NvInferPluginUtils.h>
using namespace std::chrono;
int main(int argc, const char* argv[]) {
if (argc != 3) {
std::cerr << "Usage: " << argv[0] << " <model_path> <input_shape>" << std::endl;
return 1;
}
const std::string model_path = argv[1];
const std::string input_shape_str = argv[2];
const std::vector<int64_t> input_shape = parse_input_shape(input_shape_str);
// Load the model
std::shared_ptr<torch::jit::script::Module> module = torch::jit::load(model_path);
// Create the input tensor
torch::Tensor input = torch::randn(input_shape);
// Warm up the GPU
module->forward({input}).toTensor();
// Convert the model to TensorRT
const int max_batch_size = 1;
const int max_workspace_size = 1 << 30; // 1 GB
const int max_dla_batch_size = 0;
const int max_dla_core = -1;
const bool fp16_mode = true;
const bool int8_mode = false;
const int int8_calibration_batch_size = 0;
const std::string engine_path = "engine.trt";
nvinfer1::ICudaEngine* engine = convert_to_tensorrt(module, input_shape, max_batch_size, max_workspace_size,
max_dla_batch_size, max_dla_core, fp16_mode, int8_mode,
int8_calibration_batch_size, engine_path);
// Create execution context
nvinfer1::IExecutionContext* context = engine->createExecutionContext();
// Allocate the output tensor
std::vector<int64_t> output_shape = get_output_shape(engine, input_shape);
torch::Tensor output = torch::empty(output_shape);
// Run inference using TensorRT
auto start = high_resolution_clock::now();
std::vector<void*> buffers(2);
const int input_index = engine->getBindingIndex("input");
const int output_index = engine->getBindingIndex("output");
buffers[input_index] = input.data_ptr();
buffers[output_index] = output.data_ptr();
context->executeV2(buffers.data());
auto stop = high_resolution_clock::now();
auto duration = duration_cast<microseconds>(stop - start);
std::cout << "Inference time: " << duration.count() << " microseconds" << std::endl;
// Verify the output
torch::Tensor expected_output = module->forward({input}).toTensor();
assert(torch::allclose(output, expected_output, 1e-3, 1e-3));
// Clean up
context->destroy();
engine->destroy();
return 0;
}
```
代码中的 `parse_input_shape`、`convert_to_tensorrt`、`get_output_shape` 是一些辅助函数,用于解析输入形状,将模型转换为TensorRT引擎和获取输出形状。这些函数的实现可以参考官方文档。
使用时,需要在命令行中指定模型路径和输入形状,例如:`./my_app my_model.pt 1,3,224,224`。程序会自动将模型转换为TensorRT引擎,并运行推理。最后,程序会验证TensorRT输出是否与PyTorch输出一致,以确保结果正确。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)