0

Disclaimer that I know nothing about C++ so bear with me... I am looking at some existing code which prints a continuous stream of strings describing the position of a VR controller.

void CMainApplication::printDevicePositionalData(const char * deviceName, vr::HmdMatrix34_t posMatrix, vr::HmdVector3_t position, vr::HmdQuaternion_t quaternion)
{
    LARGE_INTEGER qpc; // Query Performance Counter for Acquiring high-resolution time stamps.
                       // From MSDN: "QPC is typically the best method to use to time-stamp events and 
                       // measure small time intervals that occur on the same system or virtual machine.
    QueryPerformanceCounter(&qpc);
 
    // Print position and quaternion (rotation).
    dprintf("\n%lld, %s, x = %.5f, y = %.5f, z = %.5f, qw = %.5f, qx = %.5f, qy = %.5f, qz = %.5f",
        qpc.QuadPart, deviceName,
        position.v[0], position.v[1], position.v[2],
        quaternion.w, quaternion.x, quaternion.y, quaternion.z);
}

When I run the compiled exe in powershell it does not seem to print anything. Only if I run .\this_program.exe | tee output.txt do I see anything, as it simultaneously writes to a .txt file.

How can I change to above code to return these values, as I want to be able to read them in realtime with python using subprocess and stdout. Thanks

Dude
  • 145
  • 1
  • 9

1 Answers1

2

If you want to print to the console output, you should not be using:

dprintf - This function prints a formatted string to the command window for the debugger.

With C++, IO streams should be used (std::cout, std::clog, or std::cerr). Or fallback to printf.

Robert Andrzejuk
  • 5,076
  • 2
  • 22
  • 31