Warning - warning - I don't know what I'm doing
Just found this help system look at random.
RunThrough has never been used before ... it seems to do what you want anyway.
Clear["Global`*"]; a := b; c := 2 a + b; mathcommand = StringReplace[First[$CommandLine], "MathKernel" -> "math"]; outputfile = "c:\\rtout"; RunThrough[mathcommand <> " -noprompt", Unevaluated[Put[Definition[c], "c:\\rtout"]]] FilePrint[outputfile] Clear[a, c]; << "c:\\rtout" DeleteFile[outputfile] ?c
Output
c := 2*a + b _______________________________ Global`c c:=2 a+b
Edit .. Works with small Hold-Fu lists
Clear["Global`*"]; (*Trick here *) f[l_] := Definition @@ HoldPattern /@ Unevaluated@l ; SetAttributes[f, HoldFirst]; a := b; c := 2 a + b; d := 3 a + b; mathcommand = StringReplace[First[$CommandLine], "MathKernel" -> "math"]; outputfile = "c:\\rtout"; RunThrough[mathcommand <> " -noprompt",Unevaluated[Put[Evaluate[ f@ {c, d}], "c:\\rtout"]]] (* test *) FilePrint[outputfile] Clear[a, c, d]; << "c:\\rtout" DeleteFile[outputfile] ?c ?d
source share