Running a Rust program that is outside of the current directoryRust package with both a library and a binary?How can a Rust program access metadata from its Cargo package?Why are Rust executables so huge?How can I use regexes in Rust without Cargo?Rust compiler can't find crate for 'std'How to package source code from outside the project directory with Cargo?Using Cargo with my project's own directory structureIs there some way that rust-cargo put DLL file into exe program?How to avoid hard-coded values in RustInconsistent build behaviours in Rust on macOS Mojave 10.14.2

What are ways to record who took the pictures if a camera is used by multiple people?

'spazieren' - walking in a silly and affected manner?

Necessity of tenure for lifetime academic research

Was a six-engine 747 ever seriously considered by Boeing?

Who declared the Last Alliance to be the "last" and why?

Why does the U.S. military maintain their own weather satellites?

Eliminate key lookup in execution plan

What was Captain Marvel supposed to do once she reached her destination?

Why are JWST optics not enclosed like HST?

Is the word 'mistake' a concrete or abstract noun?

Find the logic in first 2 statements to give the answer for the third statement

Is Borg adaptation only temporary?

How to save money by shopping at a variety of grocery stores?

Break down the phrase "shitsurei shinakereba naranaindesu"

What's the origin of the concept of alternate dimensions/realities?

Am I required to correct my opponent's assumptions about my morph creatures?

How to differentiate between two people with the same name in a story?

Why is there no Disney logo in MCU movies?

How to investigate an unknown 1.5GB file named "sudo" in my Linux home directory?

Coupling two 15 Amp circuit breaker for 20 Amp

German equivalent to "going down the rabbit hole"

How can I improve my formal definitions

What is a "hashed transaction" in SQL Server Replication terminology?

Heavy Box Stacking



Running a Rust program that is outside of the current directory


Rust package with both a library and a binary?How can a Rust program access metadata from its Cargo package?Why are Rust executables so huge?How can I use regexes in Rust without Cargo?Rust compiler can't find crate for 'std'How to package source code from outside the project directory with Cargo?Using Cargo with my project's own directory structureIs there some way that rust-cargo put DLL file into exe program?How to avoid hard-coded values in RustInconsistent build behaviours in Rust on macOS Mojave 10.14.2






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








-2















How do I execute a Rust program when I am not currently inside the directory that holds the program? If I want to be in the Downloads/ directory and run a Rust file that is in the Desktop/ directory, how do I use cargo run? I assumed I could do something like cargo run <path of rust file>.










share|improve this question





















  • 1





    What do you mean with a rust file and a rust program? An entire rust project or a standalone main.rs or are you asking how to run a precompiled binary (.exe)?

    – Optimistic Peach
    Jan 25 at 21:34






  • 3





    As Optimistic Peach already mentioned, you need to add a bit more information to your question. If you are asking about compiled binaries, the question is not Rust specific, but rather operation system specific. If it's not compiled yet, we need to know if it's a Cargo project or a single Rust file.

    – Lukas Kalbertodt
    Jan 26 at 9:48

















-2















How do I execute a Rust program when I am not currently inside the directory that holds the program? If I want to be in the Downloads/ directory and run a Rust file that is in the Desktop/ directory, how do I use cargo run? I assumed I could do something like cargo run <path of rust file>.










share|improve this question





















  • 1





    What do you mean with a rust file and a rust program? An entire rust project or a standalone main.rs or are you asking how to run a precompiled binary (.exe)?

    – Optimistic Peach
    Jan 25 at 21:34






  • 3





    As Optimistic Peach already mentioned, you need to add a bit more information to your question. If you are asking about compiled binaries, the question is not Rust specific, but rather operation system specific. If it's not compiled yet, we need to know if it's a Cargo project or a single Rust file.

    – Lukas Kalbertodt
    Jan 26 at 9:48













-2












-2








-2








How do I execute a Rust program when I am not currently inside the directory that holds the program? If I want to be in the Downloads/ directory and run a Rust file that is in the Desktop/ directory, how do I use cargo run? I assumed I could do something like cargo run <path of rust file>.










share|improve this question
















How do I execute a Rust program when I am not currently inside the directory that holds the program? If I want to be in the Downloads/ directory and run a Rust file that is in the Desktop/ directory, how do I use cargo run? I assumed I could do something like cargo run <path of rust file>.







rust rust-cargo






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 26 at 9:44









Lukas Kalbertodt

31.3k5 gold badges78 silver badges141 bronze badges




31.3k5 gold badges78 silver badges141 bronze badges










asked Jan 25 at 21:22









Joshua NorrisJoshua Norris

72 bronze badges




72 bronze badges










  • 1





    What do you mean with a rust file and a rust program? An entire rust project or a standalone main.rs or are you asking how to run a precompiled binary (.exe)?

    – Optimistic Peach
    Jan 25 at 21:34






  • 3





    As Optimistic Peach already mentioned, you need to add a bit more information to your question. If you are asking about compiled binaries, the question is not Rust specific, but rather operation system specific. If it's not compiled yet, we need to know if it's a Cargo project or a single Rust file.

    – Lukas Kalbertodt
    Jan 26 at 9:48












  • 1





    What do you mean with a rust file and a rust program? An entire rust project or a standalone main.rs or are you asking how to run a precompiled binary (.exe)?

    – Optimistic Peach
    Jan 25 at 21:34






  • 3





    As Optimistic Peach already mentioned, you need to add a bit more information to your question. If you are asking about compiled binaries, the question is not Rust specific, but rather operation system specific. If it's not compiled yet, we need to know if it's a Cargo project or a single Rust file.

    – Lukas Kalbertodt
    Jan 26 at 9:48







1




1





What do you mean with a rust file and a rust program? An entire rust project or a standalone main.rs or are you asking how to run a precompiled binary (.exe)?

– Optimistic Peach
Jan 25 at 21:34





What do you mean with a rust file and a rust program? An entire rust project or a standalone main.rs or are you asking how to run a precompiled binary (.exe)?

– Optimistic Peach
Jan 25 at 21:34




3




3





As Optimistic Peach already mentioned, you need to add a bit more information to your question. If you are asking about compiled binaries, the question is not Rust specific, but rather operation system specific. If it's not compiled yet, we need to know if it's a Cargo project or a single Rust file.

– Lukas Kalbertodt
Jan 26 at 9:48





As Optimistic Peach already mentioned, you need to add a bit more information to your question. If you are asking about compiled binaries, the question is not Rust specific, but rather operation system specific. If it's not compiled yet, we need to know if it's a Cargo project or a single Rust file.

– Lukas Kalbertodt
Jan 26 at 9:48












2 Answers
2






active

oldest

votes


















1















To run a Rust file without dependencies, you can do so on a shell/command prompt.



Go to directory that looks like so:



Directory
-> main.rs


Run



rustc ./main.rs


This will spit out main (main.exe on Windows) and you can run that normally as ./main (./main.exe on Windows)




If you want to use Cargo, you'll have to create a Cargo.toml for it and put the Rust file into the src/ directory.




If you want to not be in the same directory as the Rust file, then you can do



rustc "<path/to/your/file>/main.rs"





share|improve this answer


































    2















    You can use the --manifest-path argument on cargo run to specify the path to Cargo.toml (sources files will be resolved relative to that).



    For example:



    $ cargo run --manifest-path ~/Desktop/src/myapp/Cargo.toml -- <program arguments>


    Note that if you have a rustup toolchain override on the directory containing Cargo.toml, it will not be taken into account.






    share|improve this answer



























      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      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: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      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%2fstackoverflow.com%2fquestions%2f54372941%2frunning-a-rust-program-that-is-outside-of-the-current-directory%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1















      To run a Rust file without dependencies, you can do so on a shell/command prompt.



      Go to directory that looks like so:



      Directory
      -> main.rs


      Run



      rustc ./main.rs


      This will spit out main (main.exe on Windows) and you can run that normally as ./main (./main.exe on Windows)




      If you want to use Cargo, you'll have to create a Cargo.toml for it and put the Rust file into the src/ directory.




      If you want to not be in the same directory as the Rust file, then you can do



      rustc "<path/to/your/file>/main.rs"





      share|improve this answer































        1















        To run a Rust file without dependencies, you can do so on a shell/command prompt.



        Go to directory that looks like so:



        Directory
        -> main.rs


        Run



        rustc ./main.rs


        This will spit out main (main.exe on Windows) and you can run that normally as ./main (./main.exe on Windows)




        If you want to use Cargo, you'll have to create a Cargo.toml for it and put the Rust file into the src/ directory.




        If you want to not be in the same directory as the Rust file, then you can do



        rustc "<path/to/your/file>/main.rs"





        share|improve this answer





























          1














          1










          1









          To run a Rust file without dependencies, you can do so on a shell/command prompt.



          Go to directory that looks like so:



          Directory
          -> main.rs


          Run



          rustc ./main.rs


          This will spit out main (main.exe on Windows) and you can run that normally as ./main (./main.exe on Windows)




          If you want to use Cargo, you'll have to create a Cargo.toml for it and put the Rust file into the src/ directory.




          If you want to not be in the same directory as the Rust file, then you can do



          rustc "<path/to/your/file>/main.rs"





          share|improve this answer















          To run a Rust file without dependencies, you can do so on a shell/command prompt.



          Go to directory that looks like so:



          Directory
          -> main.rs


          Run



          rustc ./main.rs


          This will spit out main (main.exe on Windows) and you can run that normally as ./main (./main.exe on Windows)




          If you want to use Cargo, you'll have to create a Cargo.toml for it and put the Rust file into the src/ directory.




          If you want to not be in the same directory as the Rust file, then you can do



          rustc "<path/to/your/file>/main.rs"






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 27 at 23:03









          Shepmaster

          178k22 gold badges393 silver badges558 bronze badges




          178k22 gold badges393 silver badges558 bronze badges










          answered Jan 25 at 21:33









          Optimistic PeachOptimistic Peach

          7307 silver badges20 bronze badges




          7307 silver badges20 bronze badges


























              2















              You can use the --manifest-path argument on cargo run to specify the path to Cargo.toml (sources files will be resolved relative to that).



              For example:



              $ cargo run --manifest-path ~/Desktop/src/myapp/Cargo.toml -- <program arguments>


              Note that if you have a rustup toolchain override on the directory containing Cargo.toml, it will not be taken into account.






              share|improve this answer





























                2















                You can use the --manifest-path argument on cargo run to specify the path to Cargo.toml (sources files will be resolved relative to that).



                For example:



                $ cargo run --manifest-path ~/Desktop/src/myapp/Cargo.toml -- <program arguments>


                Note that if you have a rustup toolchain override on the directory containing Cargo.toml, it will not be taken into account.






                share|improve this answer



























                  2














                  2










                  2









                  You can use the --manifest-path argument on cargo run to specify the path to Cargo.toml (sources files will be resolved relative to that).



                  For example:



                  $ cargo run --manifest-path ~/Desktop/src/myapp/Cargo.toml -- <program arguments>


                  Note that if you have a rustup toolchain override on the directory containing Cargo.toml, it will not be taken into account.






                  share|improve this answer













                  You can use the --manifest-path argument on cargo run to specify the path to Cargo.toml (sources files will be resolved relative to that).



                  For example:



                  $ cargo run --manifest-path ~/Desktop/src/myapp/Cargo.toml -- <program arguments>


                  Note that if you have a rustup toolchain override on the directory containing Cargo.toml, it will not be taken into account.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 26 at 13:01









                  Francis GagnéFrancis Gagné

                  35.8k2 gold badges81 silver badges87 bronze badges




                  35.8k2 gold badges81 silver badges87 bronze badges






























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • 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.

                      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%2fstackoverflow.com%2fquestions%2f54372941%2frunning-a-rust-program-that-is-outside-of-the-current-directory%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

                      Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                      SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                      은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현