如何获取正在运行的进程的命令行参数

时间:2022-09-20 20:57:23

In my program, I have been receiving an error when I use a command-line compile command for mxmlc. The error is related to an embedded font name not being correctly identified by flex in the system fonts list.

在我的程序中,当我对mxmlc使用命令行编译命令时,我一直收到错误。该错误与系统字体列表中未通过flex正确识别的嵌入字体名称有关。

However, on a whim, I decided to copy the code to Flex Builder and compile it there. To my surprise, it worked, and it found the proper font using the same system name I had given (PMingLiU).

但是,一时兴起,我决定将代码复制到Flex Builder并在那里编译。令我惊讶的是,它起了作用,它使用我给出的相同系统名称(PMingLiU)找到了正确的字体。

I suspected my problem may be a locale one, and that my system cannot correctly identify the font name because of locale considerations.

我怀疑我的问题可能是一个区域设置,并且由于区域设置的考虑,我的系统无法正确识别字体名称。

I've tried setting the locale of the compile code to en_US, to no avail. So I would like to ask if anyone here knows how exactly Flex Builder invokes the MXML compiler and what differences there are compared to running mxmlc directly? We know it's not using the mxmlc.exe directly, since we tried replacing mxmlc with our own executable to capture the command line parameters.

我已经尝试将编译代码的语言环境设置为en_US,但无济于事。所以我想问一下,这里是否有人知道Flex Builder如何调用MXML编译器,以及与直接运行mxmlc相比有何不同?我们知道它没有直接使用mxmlc.exe,因为我们尝试用我们自己的可执行文件替换mxmlc来捕获命令行参数。

If it matters, the OS used is Windows XP.

如果重要,使用的操作系统是Windows XP。

1 个解决方案

#1


1  

Although I don't have the exact answer to your question (what command line arguments Flex Builder passes to mxmlc.exe), I do have a meta-answer for you. You can find the command line by using one of two methods.

虽然我没有确切的答案(Flex Builder传递给mxmlc.exe的命令行参数),但我确实有一个元答案。您可以使用以下两种方法之一找到命令行。

The first is platform-agnostic but will require you to compile a small C++ program. I've used this approach before when solving similar problems. What you can do is create a wrapper application which simply outputs the command line to a file. Build this application and drop it in as a temporary replacement for your mxmlc.exe, and when Flex Builder executes it you'll be able to access the resulting file "cmdline.txt" to get the full command line that it was called with:

第一个是平台无关的,但需要你编译一个小的C ++程序。在解决类似问题之前我曾经使用过这种方法。你可以做的是创建一个包装器应用程序,它只是将命令行输出到一个文件。构建此应用程序并将其作为mxmlc.exe的临时替代品放入,当Flex Builder执行它时,您将能够访问生成的文件“cmdline.txt”以获取调用它的完整命令行:

#include <iostream>
#include <fstream>
using namespace std;

int main(int argc, char* argv[])
{
  ofstream cmdLine;
  cmdLine.open("cmdline.txt");

  for (int i = 0; i < argc; i++) {
    cmdLine << argv[i];
    if (i < argc)
      cmdLine << " ";
  }

  cmdLine.close();
  return 0;
}

If you don't feel right about playing this dirty trick on Flex Builder, there is an alternative assuming you're running on Windows. You can use WMI to iterate over all of the running processes and grab their command line information. Ruby being my language of choice, this would require you to install the Ruby interpreter for Windows which you can do easily with the One-Click Ruby Installer for Windows.

如果你不喜欢在Flex Builder上玩这个肮脏的技巧,那么假设你在Windows上运行,还有另一种选择。您可以使用WMI迭代所有正在运行的进程并获取其命令行信息。 Ruby是我的首选语言,这需要您安装适用于Windows的Ruby解释器,您可以使用One-Click Ruby Installer for Windows轻松完成。

After installing, just run this script as soon as Flex Builder kicks off your build:

安装完成后,只要Flex Builder启动构建,就运行此脚本:

require 'win32ole'
wmi = WIN32OLE.connect("winmgmts://")
processes = wmi.ExecQuery("select * from win32_process")

for process in processes do
    cmdLine = process.CommandLine
    puts "Command line: #{cmdLine}" if cmdLine =~ /mxmlc/
end

I've added in a regular expression to print out the command line only for processes which were started with "mxmlc" in the command line (which should work for your needs). For a more general solution of iterating over each process, just remove the if clause at the end of the line containing:

我已经添加了一个正则表达式来打印命令行,仅用于在命令行中使用“mxmlc”启动的进程(这应该适合您的需要)。有关迭代每个进程的更一般的解决方案,只需删除包含以下内容的行末尾的if子句:

puts "Command line: #{cmdLine}" if cmdLine =~ /mxmlc/

This will save you the headache of doing any low-level magic with StartRemoteThread and navigating through the PEB structures.

这将使您免于使用StartRemoteThread进行任何低级魔术并在PEB结构中导航。

That's about the best I could do considering the nature of your question and without more information regarding your development OS. If this solves your problem I might suggest that you edit your post so that people facing similar issues can find this solution. A title like "How to get command line arguments for a running process" might be more apt.

考虑到您的问题的性质以及没有关于您的开发操作系统的更多信息,这是我能做的最好的事情。如果这解决了您的问题,我可能会建议您编辑您的帖子,以便面临类似问题的人可以找到此解决方案。像“如何获取正在运行的进程的命令行参数”之类的标题可能更合适。

#1


1  

Although I don't have the exact answer to your question (what command line arguments Flex Builder passes to mxmlc.exe), I do have a meta-answer for you. You can find the command line by using one of two methods.

虽然我没有确切的答案(Flex Builder传递给mxmlc.exe的命令行参数),但我确实有一个元答案。您可以使用以下两种方法之一找到命令行。

The first is platform-agnostic but will require you to compile a small C++ program. I've used this approach before when solving similar problems. What you can do is create a wrapper application which simply outputs the command line to a file. Build this application and drop it in as a temporary replacement for your mxmlc.exe, and when Flex Builder executes it you'll be able to access the resulting file "cmdline.txt" to get the full command line that it was called with:

第一个是平台无关的,但需要你编译一个小的C ++程序。在解决类似问题之前我曾经使用过这种方法。你可以做的是创建一个包装器应用程序,它只是将命令行输出到一个文件。构建此应用程序并将其作为mxmlc.exe的临时替代品放入,当Flex Builder执行它时,您将能够访问生成的文件“cmdline.txt”以获取调用它的完整命令行:

#include <iostream>
#include <fstream>
using namespace std;

int main(int argc, char* argv[])
{
  ofstream cmdLine;
  cmdLine.open("cmdline.txt");

  for (int i = 0; i < argc; i++) {
    cmdLine << argv[i];
    if (i < argc)
      cmdLine << " ";
  }

  cmdLine.close();
  return 0;
}

If you don't feel right about playing this dirty trick on Flex Builder, there is an alternative assuming you're running on Windows. You can use WMI to iterate over all of the running processes and grab their command line information. Ruby being my language of choice, this would require you to install the Ruby interpreter for Windows which you can do easily with the One-Click Ruby Installer for Windows.

如果你不喜欢在Flex Builder上玩这个肮脏的技巧,那么假设你在Windows上运行,还有另一种选择。您可以使用WMI迭代所有正在运行的进程并获取其命令行信息。 Ruby是我的首选语言,这需要您安装适用于Windows的Ruby解释器,您可以使用One-Click Ruby Installer for Windows轻松完成。

After installing, just run this script as soon as Flex Builder kicks off your build:

安装完成后,只要Flex Builder启动构建,就运行此脚本:

require 'win32ole'
wmi = WIN32OLE.connect("winmgmts://")
processes = wmi.ExecQuery("select * from win32_process")

for process in processes do
    cmdLine = process.CommandLine
    puts "Command line: #{cmdLine}" if cmdLine =~ /mxmlc/
end

I've added in a regular expression to print out the command line only for processes which were started with "mxmlc" in the command line (which should work for your needs). For a more general solution of iterating over each process, just remove the if clause at the end of the line containing:

我已经添加了一个正则表达式来打印命令行,仅用于在命令行中使用“mxmlc”启动的进程(这应该适合您的需要)。有关迭代每个进程的更一般的解决方案,只需删除包含以下内容的行末尾的if子句:

puts "Command line: #{cmdLine}" if cmdLine =~ /mxmlc/

This will save you the headache of doing any low-level magic with StartRemoteThread and navigating through the PEB structures.

这将使您免于使用StartRemoteThread进行任何低级魔术并在PEB结构中导航。

That's about the best I could do considering the nature of your question and without more information regarding your development OS. If this solves your problem I might suggest that you edit your post so that people facing similar issues can find this solution. A title like "How to get command line arguments for a running process" might be more apt.

考虑到您的问题的性质以及没有关于您的开发操作系统的更多信息,这是我能做的最好的事情。如果这解决了您的问题,我可能会建议您编辑您的帖子,以便面临类似问题的人可以找到此解决方案。像“如何获取正在运行的进程的命令行参数”之类的标题可能更合适。