Supressing Null in a Do-loop












1












$begingroup$


I'm trying write a Do-loop that creates batch files that run .exe files with input parameters. I have to rename to *.bat since Export doesn't like outputting batch files. The output produces batch files with the text of the form:



Analyze.exe Calibration_# Null [input parameters]


which doesn't run due to the Null.



How would I go about suppressing the Null in this case?



I'd also like to change input parameters, but it seems that Do likes inserting Null. I've tried DeleteCases Null, but it's baked into the string, so that doesn't work.



Do[
shotN = n;

DeleteFile[{"1.bat", "2.bat"}];
Export["1.txt",
StringReplace[
"Analyze1.exe Calibration_xx [input parameters]",
"xx" -> ToString[shotN]]];

Export["2.txt",
StringReplace[
"Analyze2.exe Calibration_xx [input parameters]",
"xx" -> ToString[shotN]]];

RenameFile["1.txt", "1.bat"];
RenameFile["2.txt", "2.bat"];

Run["1.bat"]
Run["2.bat"]

, {n, 1, 10}]









share|improve this question











$endgroup$








  • 2




    $begingroup$
    Try Export["filename.bat", <<string>>, "Text"]. That should get you rid of the need for Rename. And separate the Runs by semicoli (;).
    $endgroup$
    – Henrik Schumacher
    4 hours ago












  • $begingroup$
    That seemed to do the trick! Many thanks!
    $endgroup$
    – 2close2see
    4 hours ago
















1












$begingroup$


I'm trying write a Do-loop that creates batch files that run .exe files with input parameters. I have to rename to *.bat since Export doesn't like outputting batch files. The output produces batch files with the text of the form:



Analyze.exe Calibration_# Null [input parameters]


which doesn't run due to the Null.



How would I go about suppressing the Null in this case?



I'd also like to change input parameters, but it seems that Do likes inserting Null. I've tried DeleteCases Null, but it's baked into the string, so that doesn't work.



Do[
shotN = n;

DeleteFile[{"1.bat", "2.bat"}];
Export["1.txt",
StringReplace[
"Analyze1.exe Calibration_xx [input parameters]",
"xx" -> ToString[shotN]]];

Export["2.txt",
StringReplace[
"Analyze2.exe Calibration_xx [input parameters]",
"xx" -> ToString[shotN]]];

RenameFile["1.txt", "1.bat"];
RenameFile["2.txt", "2.bat"];

Run["1.bat"]
Run["2.bat"]

, {n, 1, 10}]









share|improve this question











$endgroup$








  • 2




    $begingroup$
    Try Export["filename.bat", <<string>>, "Text"]. That should get you rid of the need for Rename. And separate the Runs by semicoli (;).
    $endgroup$
    – Henrik Schumacher
    4 hours ago












  • $begingroup$
    That seemed to do the trick! Many thanks!
    $endgroup$
    – 2close2see
    4 hours ago














1












1








1





$begingroup$


I'm trying write a Do-loop that creates batch files that run .exe files with input parameters. I have to rename to *.bat since Export doesn't like outputting batch files. The output produces batch files with the text of the form:



Analyze.exe Calibration_# Null [input parameters]


which doesn't run due to the Null.



How would I go about suppressing the Null in this case?



I'd also like to change input parameters, but it seems that Do likes inserting Null. I've tried DeleteCases Null, but it's baked into the string, so that doesn't work.



Do[
shotN = n;

DeleteFile[{"1.bat", "2.bat"}];
Export["1.txt",
StringReplace[
"Analyze1.exe Calibration_xx [input parameters]",
"xx" -> ToString[shotN]]];

Export["2.txt",
StringReplace[
"Analyze2.exe Calibration_xx [input parameters]",
"xx" -> ToString[shotN]]];

RenameFile["1.txt", "1.bat"];
RenameFile["2.txt", "2.bat"];

Run["1.bat"]
Run["2.bat"]

, {n, 1, 10}]









share|improve this question











$endgroup$




I'm trying write a Do-loop that creates batch files that run .exe files with input parameters. I have to rename to *.bat since Export doesn't like outputting batch files. The output produces batch files with the text of the form:



Analyze.exe Calibration_# Null [input parameters]


which doesn't run due to the Null.



How would I go about suppressing the Null in this case?



I'd also like to change input parameters, but it seems that Do likes inserting Null. I've tried DeleteCases Null, but it's baked into the string, so that doesn't work.



Do[
shotN = n;

DeleteFile[{"1.bat", "2.bat"}];
Export["1.txt",
StringReplace[
"Analyze1.exe Calibration_xx [input parameters]",
"xx" -> ToString[shotN]]];

Export["2.txt",
StringReplace[
"Analyze2.exe Calibration_xx [input parameters]",
"xx" -> ToString[shotN]]];

RenameFile["1.txt", "1.bat"];
RenameFile["2.txt", "2.bat"];

Run["1.bat"]
Run["2.bat"]

, {n, 1, 10}]






export






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 4 hours ago









m_goldberg

86k872196




86k872196










asked 4 hours ago









2close2see2close2see

333




333








  • 2




    $begingroup$
    Try Export["filename.bat", <<string>>, "Text"]. That should get you rid of the need for Rename. And separate the Runs by semicoli (;).
    $endgroup$
    – Henrik Schumacher
    4 hours ago












  • $begingroup$
    That seemed to do the trick! Many thanks!
    $endgroup$
    – 2close2see
    4 hours ago














  • 2




    $begingroup$
    Try Export["filename.bat", <<string>>, "Text"]. That should get you rid of the need for Rename. And separate the Runs by semicoli (;).
    $endgroup$
    – Henrik Schumacher
    4 hours ago












  • $begingroup$
    That seemed to do the trick! Many thanks!
    $endgroup$
    – 2close2see
    4 hours ago








2




2




$begingroup$
Try Export["filename.bat", <<string>>, "Text"]. That should get you rid of the need for Rename. And separate the Runs by semicoli (;).
$endgroup$
– Henrik Schumacher
4 hours ago






$begingroup$
Try Export["filename.bat", <<string>>, "Text"]. That should get you rid of the need for Rename. And separate the Runs by semicoli (;).
$endgroup$
– Henrik Schumacher
4 hours ago














$begingroup$
That seemed to do the trick! Many thanks!
$endgroup$
– 2close2see
4 hours ago




$begingroup$
That seemed to do the trick! Many thanks!
$endgroup$
– 2close2see
4 hours ago










1 Answer
1






active

oldest

votes


















3












$begingroup$

The Runs need to be separated by semicoli. Moreover, you may use the export filter "Text" independent of the file type. This removes the need (i) to delete potentially preexistent files and (ii) to rename the files after export. Also StringJoin (<>) might become your friend.



Do[
Export[
"1.bat",
"Analyze1.exe Calibration_" <> ToString[n] <> " [input parameters]",
"Text"];
Export[
"2.bat",
"Analyze2.exe Calibration_" <> ToString[n] <> " [input parameters]",
"Text"];
Run["1.bat"];
Run["2.bat"];
, {n, 1, 10}]





share|improve this answer









$endgroup$













    Your Answer





    StackExchange.ifUsing("editor", function () {
    return StackExchange.using("mathjaxEditing", function () {
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    });
    });
    }, "mathjax-editing");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "387"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f191427%2fsupressing-null-in-a-do-loop%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3












    $begingroup$

    The Runs need to be separated by semicoli. Moreover, you may use the export filter "Text" independent of the file type. This removes the need (i) to delete potentially preexistent files and (ii) to rename the files after export. Also StringJoin (<>) might become your friend.



    Do[
    Export[
    "1.bat",
    "Analyze1.exe Calibration_" <> ToString[n] <> " [input parameters]",
    "Text"];
    Export[
    "2.bat",
    "Analyze2.exe Calibration_" <> ToString[n] <> " [input parameters]",
    "Text"];
    Run["1.bat"];
    Run["2.bat"];
    , {n, 1, 10}]





    share|improve this answer









    $endgroup$


















      3












      $begingroup$

      The Runs need to be separated by semicoli. Moreover, you may use the export filter "Text" independent of the file type. This removes the need (i) to delete potentially preexistent files and (ii) to rename the files after export. Also StringJoin (<>) might become your friend.



      Do[
      Export[
      "1.bat",
      "Analyze1.exe Calibration_" <> ToString[n] <> " [input parameters]",
      "Text"];
      Export[
      "2.bat",
      "Analyze2.exe Calibration_" <> ToString[n] <> " [input parameters]",
      "Text"];
      Run["1.bat"];
      Run["2.bat"];
      , {n, 1, 10}]





      share|improve this answer









      $endgroup$
















        3












        3








        3





        $begingroup$

        The Runs need to be separated by semicoli. Moreover, you may use the export filter "Text" independent of the file type. This removes the need (i) to delete potentially preexistent files and (ii) to rename the files after export. Also StringJoin (<>) might become your friend.



        Do[
        Export[
        "1.bat",
        "Analyze1.exe Calibration_" <> ToString[n] <> " [input parameters]",
        "Text"];
        Export[
        "2.bat",
        "Analyze2.exe Calibration_" <> ToString[n] <> " [input parameters]",
        "Text"];
        Run["1.bat"];
        Run["2.bat"];
        , {n, 1, 10}]





        share|improve this answer









        $endgroup$



        The Runs need to be separated by semicoli. Moreover, you may use the export filter "Text" independent of the file type. This removes the need (i) to delete potentially preexistent files and (ii) to rename the files after export. Also StringJoin (<>) might become your friend.



        Do[
        Export[
        "1.bat",
        "Analyze1.exe Calibration_" <> ToString[n] <> " [input parameters]",
        "Text"];
        Export[
        "2.bat",
        "Analyze2.exe Calibration_" <> ToString[n] <> " [input parameters]",
        "Text"];
        Run["1.bat"];
        Run["2.bat"];
        , {n, 1, 10}]






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 4 hours ago









        Henrik SchumacherHenrik Schumacher

        53.2k471148




        53.2k471148






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Mathematica Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            Use MathJax to format equations. MathJax reference.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f191427%2fsupressing-null-in-a-do-loop%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Knooppunt Holsloot

            Altaar (religie)

            Gregoriusmis