Roy Tang

Programmer, engineer, scientist, critic, gamer, dreamer, and kid-at-heart.

Blog Notes Photos Links Archives About

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.

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).

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.

If it matters, the OS used is Windows XP.

Comments

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.

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:

#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.

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

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:

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.

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.