During his July trip to Iraq, Sen. Barack Obama met with a man who represents both an opportunity and an obstacle to his presidency: Army Gen. David H. Petraeus. Petraeus, a hero to many Americans for his management of the war in Iraq, argued in a private briefing that military commanders should be given wide latitude in handing the future course of the war — though Obama was running for president on a platform calling for a withdrawal of combat troops in 16 months.

The meeting offered a test for a relationship that might help define Obama’s term in office. Though he’s talked about governing in a bipartisan fashion, Obama ran for office as a progressive opposed to the Iraq war. The uniformed military, typically wary of liberals in general, is unsure what to think about Obama — and the last Democratic president, Bill Clinton, stumbled early in his relationship with the military.

Yet Obama struck a balance in the Petraeus meeting. “If I were in his shoes, I’d probably feel the same way” about preserving flexibility for military operations, Obama said of Petraeus after the meeting ended. “But my job as a candidate for president and a potential commander in chief extends beyond Iraq.”

To Peter Feaver, one of the leading scholars of civil-military relations, that comment was auspicious. “Obama had it pitch-perfect,” said Feaver, a professor of political science at Duke University and a national-security staffer for both Clinton and President George W. Bush. “Obama was right to signal to the military, ‘I want your military advice, and I will factor it into my strategic decisions, where military advice is one of my concerns.’”

Whether a Commander-in-Chief Obama can continue the tone that Candidate Obama sounded in July remains to be seen. According to interviews with active and retired military officers, Obama and the military can have a productive relationship, provided that Obama operates along some simple principles. Consult, don’t steamroll — and don’t capitulate. Be honest about disagreements, and emphasize areas of agreement. Make Petraeus a partner, not an adversary.

Similarly, the uniformed military will have to keep certain principles in mind as well. There’s only one commander in chief, and you’re not him. Don’t substitute military judgment for strategic judgment.

Obama enters office without some of the impediments to healthy civil-military relations that hindered Clinton. Clinton, a baby boomer, had to deal with the legacy of not serving in Vietnam, while Obama, born in 1961, doesn’t have the baggage of the Vietnam era weighing him down. “He didn’t serve, but he didn’t serve with distinction,” said Feaver, laughing.

Similarly damaging to Clinton was his early misstep with gays in the military. During Clinton’s transition from candidate to president, he seemed to suggest lifting the ban on gays serving openly, an implication seized on by conservatives and met with furor from the armed services. His response was to back down — which set a tone to the military that an uncertain Clinton could be rolled.

Defense Department officials today still believe Clinton’s early capitulation set a troublesome precedent. “If Clinton had simply ordered the military to lift the ban on gays in the military — as Truman did with racial integration against near universal opposition,” said one Pentagon official who requested anonymity, “he would have been much better off in dealing with the military for the rest of his administration. There would have been a big fuss, but they would have respected him more.”

The lesson for Obama, this official continued, is “not to get rolled or railroaded by the top brass, as Clinton and his civilian team were by Colin Powell,” who was chairman of the Joint Chiefs of Staff at the time. “Obama and his team need to be respectful and solicitous of senior military advice, but leave no doubt about who is in charge.”

Yet Obama doesn’t wish merely not to be railroaded. Much as with the Petraeus meeting in July, Obama’s team has signaled an openness to the military since coming to Washington. One of Obama’s first foreign-policy aides in the Senate, Mark Lippert, deployed to Iraq in 2007 as a Naval reservist. Several of his principal advisers today command widespread Pentagon respect.

Former Sen. Sam Nunn, who served as a longtime chairman of the Senate Armed Services Committee and is now an influential military reformer, is advising Obama’s Pentagon transition. Michele Flournoy, a former deputy assistant secretary of defense in the second Clinton term and prominent authority on counterinsurgency, is helping run Obama’s Pentagon headhunting process. Most important, Obama’s aides have flirted in the past week with asking Bob Gates, the current defense secretary, to stay on for an extra year.

In addition to benefiting from succeeding a widely-disliked defense secretary, Donald Rumsfeld, Gates’ brief tenure at Defense has earned plaudits from around the military, especially as he worked closely with Petraeus in implementing the troop surge in Iraq last year.

“Keeping Gates is a huge gesture to the military,” said Ian Moss, a Marine corporal who recently left active duty. “Simply put, from my conversations with military personnel, there is much respect for Gates. By retaining Gates, Obama instantly communicates to military personnel that he values their assessment of Gates.”

Feaver said the Gates trial balloon indicated that Obama doesn’t intend to govern in an “Anything But Bush” manner — rigidly rejecting every aspect of the Bush legacy as a matter of principle. “The very fact that they want to send that signal is a positive from the point of view of civil-military relations,” he said. “If it’s not a trial balloon, and they actually do it, it would further cement an emerging view of Obama as a pragmatist.”

One early decision that many in the military likely look to is whether Obama holds to his position on withdrawing from Iraq according to a fixed timetable. As with the country as a whole, there is no unanimity of opinion on Iraq within the military. But at the very least, the war is more personal to the military than it is to the civilian population. Many view this withdrawal with anxiety.

Feaver said it would be useful for Obama to blur the difference between his withdrawal proposals and Petraeus’ plan to shift the U.S. footprint to “strategic overwatch” functions, like training Iraqi troops — though Petraeus’ plan has no timetable associated with it.

“If what he’s describing is a target, a goal that’s desirable, that he’ll shoot for, and work to make conditions on the ground consistent with … then that’s not really much of a problem,” Feaver said. But if, on the other hand, Obama really does intend to withdraw two combat brigades every month — as he indicated during the Democratic presidential primaries, “then that would spark a civil-military — I won’t say crisis, but a challenge to manage,” Feaver pointed out.

Some members of the military community are more sanguine. Several say that if they disagree with the decision, they respect Obama’s authority to make it.

“In the end, we are not self-employed. And after the military leadership provides its best military advice, it is up to the policy-makers to make the decision and for the military to execute those decisions,” said a senior Army officer recently back from Iraq, who requested anonymity because he is still on active duty. “Now, if those in the military do not like the decision, they have two choices. One, salute smartly and execute the missions given them to the best of their ability. Or, the other, leave the military if they do not feel they can faithfully execute their missions. That is one way the military does get to vote in an all-volunteer force.”

Moss agreed. “The military will just follow the order,” he said. “The great majority of Americans want U.S. forces out of Iraq. This is part of the reason Obama was sent to the White House.”

Much as with Obama’s pick for secretary of defense, many in the military will watch how Obama and Petraeus interact as a barometer for civil-military harmony. To some degree, there could be an invisibility to the relationship — as the senior Army officer said, “most will not know about or see” what the president says to his Central Command chief — but it could still be closely scrutinized.

Not everyone is convinced that there will be tension between Obama and Petraeus. “I am certain Gen. Petraeus will fulfill the mission as tasked by the [secretary of defense] and the [chairman of the Joint Chiefs of Staff] without question,” said Malcolm Nance, a former instructor of Navy special forces who has spent extensive periods in Iraq and Afghanistan. “I am certain as a combat officer of great intellect, a superlative battle staff and open mindedness, his real mission is singular: break Al Qaeda and kill the Al Qaeda senior leadership. He did it in Iraq and he intends to do it in Afghanistan if given the chance.

“There will be no MacArthurs here,” Nance continued, referring to the legendary Army general whom President Harry S Truman fired for insubordination during the Korean War. And for their part, Nance predicted, “the phrase ‘pleasantly surprised’ should come to the lips of all military personnel who meet with Obama,” judging from the inclusiveness Obama showed in his campaign.

Robert Mackey, a retired Army officer, said that both Petraeus and the new Iraq commander, Gen. Ray Odierno, can work with Obama despite disagreements on Iraq. “I think that both are pretty good thinkers, more than able to understand that change is going to occur and that their job is to complete whatever mission [Obama] orders them to do,” Mackey said. “They don’t have to be Obama’s buddies to do the job. In fact, that would most likely reflect poorly on the administration within the military.”

Indeed, the differences between Obama and Petraeus or Odierno on Iraq might turn out to be healthy for civilian-military relations. Judging from how the July meeting with Petraeus in Baghdad went, “Obama should be in good shape,” said the Pentagon official. “It will be a refreshing change from recent years, when civilian political leaders have shirked off tough questions about — and responsibility for — their war policies by claiming, in effect, that they’re just taking directions from the commanders on the ground, in effect, hiding behind the skirts of the military.”

Moss agreed. Institutional pushback is “not a bad thing” necessarily, he said. “If anything, the major lesson from the past decade should be that the solutions to the challenges we face must be approached from multiple angles, and that is what Obama has signaled as his intention.”

Like Feaver, the anonymous senior Army officer expected Obama to make Petraeus a partner on Iraq and other issues. “Once President-elect Obama is in office,” the officer said, “he can very easily shift his view based on advice he has received, as well as the situation on the ground at the time, since he has left himself an out or two over time. It would be surprising to see him go completely against Gen. Petraeus, since I would think [Obama] would rather have him in uniform than out — where he would then be free to provide commentary on the decisions that have been made.”

Another challenge for Obama, beyond Petraeus and Iraq, would be senior officers’ desire “to get back to preparing — and procuring — for the big, conventional Russia-China scenario the U.S. military institutionally prefers,” the anonymous Pentagon official said. But the current financial crisis and massive budget deficits create their own pressures on defense spending. All interviewed said there was no shortage of potential pitfalls in the new Obama-military relationship. Two wars, a persistent threat from Al Qaeda, an overstretched ground force and a likely Pentagon budget crunch guarantee difficult decisions in the next four years.

“The single biggest mistake Obama could make would be to “completely discount the advice of the military senior leadership and those of his combat commanders who have the most experience dealing with the issues,” said the anonymous senior Army officer. “Even if he does not discount it, but is perceived to discount it, the relationship will be largely going back to the Clinton era, and will take years to repair. That’s not something you want to do in a time of war, which most of the nation has forgotten.”