A federal judge yesterday rejected Marine Lt. Col. Oliver L. North's attempt to derail independent counsel Lawrence E. Walsh's investigation of the Iran-contra affair and once again directed North to comply with a federal grand jury subpoena he had refused to honor two months ago.

Chief U.S. District Court Judge Aubrey E. Robinson Jr. sidestepped the constitutional questions directed at Walsh's appointment under the Ethics in Government Act and held that Walsh's backup appointment in March as a Justice Department prosecutor is valid.

Along with his ruling, Robinson issued a sealed order concerning the grand jury subpoena, which called for a sample of North's handwriting. The fired White House aide was secretly held in contempt of court May 8 for refusing, on constitutional grounds, to comply with the demand.

North's attorneys had no immediate comment, but they are expected to appeal the decision, as they did the contempt order.

The U.S. Court of Appeals granted a stay of the contempt citation May 8 and heard legal arguments on the constitutional issues last month. But then the appellate judges turned about and sent the case back to Robinson, saying that "the judiciary should rule on the constitutionality of an act of Congress only as a last resort." They told Robinson to see whether he could resolve the dispute on other grounds.

Robinson did so, ruling that Attorney General Edwin Meese III had the authority to give Walsh his parallel appointment by exercising the same powers then-Attorney General Elliot L. Richardson used in 1973 to appoint Archibald Cox special prosecutor in the Watergate scandal.

The Supreme Court affirmed that appointment the next year in the dispute over President Richard M. Nixon's tape recordings.

"The authority and independence of the Watergate special prosecutor was almost identical to that enjoyed by Mr. Walsh," Robinson said.

North's lawyers had argued that Walsh's original appointment by a special three-judge federal court under the 1978 ethics law was an unconstitutional infringement on the powers of the executive branch. They also maintained that Meese's backup appointment was unconstitutional because in making it, Meese expressly agreed not to remove Walsh except "for good cause."

Judge Robinson said that Meese, in appointing Walsh, had voluntarily restricted his discretion to remove officials at will. "This action does not violate the Constitution," he ruled.

North and his attorneys had also contended that the backup appointment by Meese violated the Ethics in Government Act because it provides that, once an independent counsel has started work, the Justice Department "shall suspend all investigations and proceedings" regarding the inquiry "except insofar as such independent counsel agrees in writing that such investigations or proceedings may be continued by the Department of Justice."

Robinson said that Walsh effectively agreed to that by executing an affidavit accepting the parallel appointment. At the same time, the judge rejected Walsh's contention that the new office of "independent counsel: Iran/contra" that Meese created for him by Justice Department regulation was still somehow "outside the Department of Justice."

"Mr. Walsh was aware of the particulars of his new office when he accepted it," Robinson said. "His misconception of where the office was located within the Executive Branch, therefore, did not negate his express acceptance of the appointment. Mr. Walsh's authority under the regulation is clear."

Both Walsh and the Justice Department welcomed the ruling, which allowed them to paper over their differences about the constitutionality of the independent counsel section of the ethics law. Walsh is committed to defending it. Justice Department officials, like North and his lawyers, have assailed it as unconstitutional.

"We very much appreciate the prompt ruling and the reassurance of continuity for our investigation," Walsh said in a brief statement.

Justice Department spokesman Terry H. Eastland praised the ruling and pointed out that the purpose of the parallel appointment "was to ensure that the independent counsel's investigation could go forward, unimpeded by concerns about the constitutionality of the Ethics in Government Act."