element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Autodesk EAGLE
  • Products
  • More
Autodesk EAGLE
EAGLE User Support (English) system("cmd.exe /c path..."); fails if path include white space, even quoted
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Autodesk EAGLE to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 3 replies
  • Subscribers 176 subscribers
  • Views 980 views
  • Users 0 members are here
Related

system("cmd.exe /c path..."); fails if path include white space, even quoted

Morosh
Morosh over 4 years ago

Hello:
I made a small ulp which invoke eaglecon from inside eagle to get eps drawing, using system("cmd.exe /c path\eaglecon etc.....");
I noticed that this command fails if the path even quoted include space (in my case "C:\EAGLE-7.7.0 x32\bin\eaglecon")

I got: Windows cannot fond '-X', Make sure you typed the name correctly and then try again.

my ulp:
string cmd,fname,bname,path,path2,rot,quick;
int i;

string convert(string dumy)
{
string dumy2,ch;
int i;

rot="";
quick="";

dumy2="";
for(i=0;i<strlen(dumy);i++) {
   ch=strsub(dumy,i,1);
   if(ch=="/") ch="\\";
   dumy2=dumy2+ch;
   }
return dumy2;
}

path=path_doc[0];
path="\""+strsub(path,0,strlen(path)-4)+"\\bin\\eaglecon"+"\"";
path=convert(path);


if(board){
   board(B){
      bname=B.name;;
      //dlgMessageBox("bname1="+bname);
      bname=convert(bname);
      //dlgMessageBox("bname2="+bname);
      fname=bname;
      fname[strlen(fname)-4]=0;
      for(i=1;i< argc; i++) {
         if(argv[i]=="rot") rot=" -r ";
         else if(argv[i]=="quick") quick=" -q+ ";
         else if(argv[i]=="sol") {
            cmd="cmd.exe /c start echo " + path + rot+quick+ " -X -f- -deps -o\""+fname+"_sol.eps\" \""+bname+"\" 16 17 18 20";
            system(cmd);
            cmd="cmd.exe /c start " + path + rot+quick+ " -X -f- -deps -o\""+fname+"_sol.eps\" \""+bname+"\" 16 17 18 20";
            system(cmd);
            }
         }

      //dlgMessageBox(cmd);
      }
   }

I've added "echo" for verification, typing the echoed string in a command window succeed.
Everything worked OK if I remove the space in "C:\EAGLE-7.7.0 x32", like "C:\EAGLE-7.7.0x32"


is there a way to resolve that?

Thanks




--
Cet email a fait l'objet d'une analyse antivirus par AVG.
http://www.avg.com

 

  • Sign in to reply
  • Cancel
  • dukepro
    dukepro over 4 years ago

    Morosh,

     

    1. In everything you do, do it do the best of your ability.

    1a. Add prolific comments, especially when presenting code to colleagues.

    1b. Use proper indents.  4 spaces for each indent level.

     

    2. Try preceding each space in /path/ with a backslash:

     

    See below.

     

    Best regards,

        - Chuck

     

    On 11/10/20 02:58, Morosh wrote:

    Hello:

    I made a small ulp which invoke eaglecon from inside eagle to get eps drawing, using system("cmd.exe /c path\eaglecon etc.....");

    I noticed that this command fails if the path even quoted include space (in my case "C:\EAGLE-7.7.0 x32\bin\eaglecon")

     

    I got: Windows cannot fond '-X', Make sure you typed the name correctly and then try again.

     

    my ulp:

    string cmd,fname,bname,path,path2,rot,quick;

    int i;

     

    string convert(string dumy)

    {

    string dumy2,ch;

    int i;

     

    rot="";

    quick="";

     

    dumy2="";

    for(i=0;i<strlen(dumy);i++) {

       ch=strsub(dumy,i,1);

       if(ch=="/") ch="
    ";

     

     

    *    if (ch==" ") ch="
    ";**

    *

       dumy2=dumy2+ch;

       }

    return dumy2;

    }

     

    path=path_doc[0];

    path="\""strsub(path,0,strlen(path)-4)"
    bin
    eaglecon"+"\"";

    path=convert(path);

     

     

    if(board){

       board(B){

          bname=B.name;;

          //dlgMessageBox("bname1="+bname);

          bname=convert(bname);

          //dlgMessageBox("bname2="+bname);

          fname=bname;

          fname[strlen(fname)-4]=0;

          for(i=1;i< argc; i++) {

             if(argv[i]=="rot") rot=" -r ";

             else if(argv[i]=="quick") quick=" -q+ ";

             else if(argv[i]=="sol") {

                cmd="cmd.exe /c start echo " + path + rotquick " -X -f- -deps -o\""fname"_sol.eps\" \""bname"\" 16 17 18 20";

                system(cmd);

                cmd="cmd.exe /c start " + path + rotquick " -X -f- -deps -o\""fname"_sol.eps\" \""bname"\" 16 17 18 20";

                system(cmd);

                }

             }

     

          //dlgMessageBox(cmd);

          }

       }

     

    I've added "echo" for verification, typing the echoed string in a command window succeed.

    Everything worked OK if I remove the space in "C:\EAGLE-7.7.0 x32", like "C:\EAGLE-7.7.0x32"

     

     

    is there a way to resolve that?

     

    Thanks

     

     

     

     

     

     

     

    Attachments:
    2742.att1.html.zip
    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • autodeskguest
    autodeskguest over 4 years ago in reply to dukepro

    On 10/11/2020 14:19, Chuck Huber wrote:

     

    2. Try preceding each space in /path/ with a backslash:

     

    I believe that would fix his problem on Mac or Linux but not on Windoze,

    where backslash is the path separator rather than an escape character.

     

    I'm sure the OP won't accept this answer but the easiest fix is to never

    use space characters in path names. They are evil for many reasons, this

    being one of them.

     

    More usefully, I will point out that this is NOT an Eagle issue but

    rather a Windows shell problem. See:

    https://stackoverflow.com/questions/6376113/how-do-i-use-spaces-in-the-command-prompt

    https://superuser.com/questions/432980/how-to-call-a-program-that-contains-space-in-filename

    https://superuser.com/questions/239565/can-i-use-the-start-command-with-spaces-in-the-path

    https://superuser.com/questions/1478512/how-do-i-pass-a-filename-with-spaces-from-wsl-to-cmd-exe

     

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Morosh
    Morosh over 4 years ago

    Thanks all for reply.

    Finally it wasn't a problem of white space, I removed it and the problem persists mysteriously (although it seems to me that it works once earlier).

    So I changed my ulp and now I create a batch file, then I run it and it's working good:

    here it's if anyone is interested:

     

    string convert(string dumy)

    {

    string dumy2,ch;

    int i;

     

    dumy2="";

    for(i=0;i<strlen(dumy);i++) {

       ch=strsub(dumy,i,1);

       if(ch=="/") ch="\\";

       dumy2=dumy2+ch;

       }

    return dumy2;

    }

     

    string fname,bname,path,rot,quick;

    int i;

     

    rot="";

    quick="";

     

    for(i=1;i< argc; i++) {

       if(argv[i]=="rot") rot=" -r ";

       if(argv[i]=="quick") quick=" -q- ";

       }

     

    path=path_doc[0];

    path="\""+strsub(path,0,strlen(path)-4)+"\\bin\\eaglecon"+"\"";

    path=convert(path);

     

    output("toto.bat"){

     

       if(board){

          board(B){

             bname=B.name;;

             bname=convert(bname);

             fname=bname;

             fname[strlen(fname)-4]=0;

             for(i=1;i< argc; i++) {

                if(argv[i]=="sol") {

                   printf("%s%s%s -X -f- -deps -o\"%s_sol.eps\" \"%s\" 16 17 18 20\n", path,rot,quick,fname,bname);

                   }

                else if (argv[i]=="cmp") {

                   printf("%s%s%s -X -f- -deps -o\"%s_cmp.eps\" \"%s\" 1 17 18 20\n", path,rot,quick,fname,bname);

                   }

                else if (argv[i]=="pls") {

                   printf("%s%s%s -X -f- -deps -o\"%s_pls.eps\" \"%s\" 20 22 26\n", path,rot,quick,fname,bname);

                   }

                else if (argv[i]=="plc") {

                   printf("%s%s%s -X -f- -deps -o\"%s_plc.eps\" \"%s\" 20 21 25\n", path,rot,quick,fname,bname);

                   }

                else if (argv[i]=="vls") {

                   printf("%s%s%s -X -f- -deps -o\"%s_vls.eps\" \"%s\" 20 22 28\n", path,rot,quick,fname,bname);

                   }

                else if (argv[i]=="vlc") {

                   printf("%s%s%s -X -f- -deps -o\"%s_vlc.eps\" \"%s\" 20 21 27\n", path,rot,quick,fname,bname);

                   }

                }  //for(i=1;i< argc; i++)

                printf("del toto.bat\n");

             }  //board(B){

          }  //if(board)

       }  //output("toto.bat")

    system("cmd.exe /c toto.bat");

     

    I'm using this way also to generate gerber files, I found it's more comfortable than cam processor

     

    Regards

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube