Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 19
  1. #1

    Come Far Avviare Un File Vbs Con Java ?

    Salve a tutti , ho la necessità di far avviare degli script vbs con java , ma i risultati per adesso sono stati deludenti .........

    Ho usato codici di questo tipo ma vanno bene solo per i file di tipo exe !!!

    Ad esempio :

    class eseguiExe
    {
    public static void main(String args[])
    {
    try{
    Runtime rt=Runtime.getRuntime();
    Process proc=rt.exec("Pluto.exe");
    }
    catch(Exception e){}
    }
    }


    Oppure :

    class eseguiExe
    {
    public static void main(String args[])
    {
    try{
    Runtime r = Runtime.getRuntime();Process p = r.exec("C:\\Olivia\\Pluto.exe");
    Process proc=r.exec("Pluto.exe");
    }
    catch(Exception e){}
    }
    }


    Potreste aiutarmi ?





    Ringrazio anticipatamente !


  2. #2
    Utente di HTML.it L'avatar di andbin
    Registrato dal
    Jan 2006
    residenza
    Italy
    Messaggi
    18,284

    Re: Come Far Avviare Un File Vbs Con Java ?

    Originariamente inviato da Runcommand
    Potreste aiutarmi ?
    Basta invocare l'interprete dei comandi e fargli eseguire lo script:

    ....exec("cmd /c tuoscript.vbs");

    cmd.exe è l'interprete dei comandi (la "shell") per i sistemi Windows NT-based (NT/2000/XP ecc..)
    Andrea, andbin.devSenior Java developerSCJP 5 (91%) • SCWCD 5 (94%)
    java.util.function Interfaces Cheat SheetJava Versions Cheat Sheet

  3. #3
    Ho seguito le tue istruzioni andbin e davvero non so come ringraziarti !!

    Funzionaaaaaaaaa !!!!!!! ................................

    Non riuscivo proprio a venir fuori da una situazione di stallo , volevo chiederti un'altra cosa :

    E possibile far avviare contemporaneamente due file vbs ?


    Saluti



  4. #4
    Utente di HTML.it L'avatar di andbin
    Registrato dal
    Jan 2006
    residenza
    Italy
    Messaggi
    18,284
    Originariamente inviato da Runcommand
    E possibile far avviare contemporaneamente due file vbs ?
    exec() esegue un comando ma non attende la sua terminazione. (per attendere la terminazione c'è waitFor() di Process).
    Quindi sei liberissimo di lanciare 2 exec una di seguito all'altra. Il "contemporaneamente", inteso come nello stesso preciso esatto momento ovviamente non è possibile.
    Andrea, andbin.devSenior Java developerSCJP 5 (91%) • SCWCD 5 (94%)
    java.util.function Interfaces Cheat SheetJava Versions Cheat Sheet

  5. #5
    Felice di risentirti andbin

    ho provato ad avviare due vbs in questo modo :

    class eseguiExe
    {
    public static void main(String args[])
    {
    try{
    Runtime r = Runtime.getRuntime();Process p = r.exec("cmd /c C:\\Picajet\\ambra\\omega.vbs");
    Process proc=r.exec("cmd /c omega.vbs");
    Runtime r = Runtime.getRuntime();Process p = r.exec("cmd /c C:\\Picajet\\ambra\\text.vbs");
    Process proc=r.exec("cmd /c text.vbs");
    }
    catch(Exception e){}
    }
    }

    ma non va !!!

    Ho provato anche così ma continua a darmi errore !!!


    class eseguiExe
    {
    public static void main(String args[])
    {
    try{
    Runtime rt=Runtime.getRuntime();
    Process proc=rt.exec("cmd /c text.vbs");
    Runtime rt=Runtime.getRuntime();
    Process proc=rt.exec("cmd /c omega.vbs");
    }
    catch(Exception e){}
    }
    }


    Pure così niente !!!

    class eseguiExe
    {
    public static void main(String args[])
    {
    try{
    Runtime rt=Runtime.getRuntime();
    Process proc=rt.exec("cmd /c text.vbs");
    Process proc=rt.exec("cmd /c omega.vbs");
    }
    catch(Exception e){}
    }
    }


    Dove sbaglio ??


    Saluti e grazie !!!!


  6. #6
    Utente di HTML.it L'avatar di andbin
    Registrato dal
    Jan 2006
    residenza
    Italy
    Messaggi
    18,284
    Originariamente inviato da Runcommand
    Dove sbaglio ??
    Non lo so ..... dipende da dove sono quei file vbs. Se passi nel comando un path assoluto (e ammesso che sia correttamente scritto), non dovresti avere problemi. (e se nel path ci fossero spazi, devi quotarlo).

    A mano riesci a lanciarli? Cioè se apri una console dei comandi e digiti il path completo allo script, funziona??
    Andrea, andbin.devSenior Java developerSCJP 5 (91%) • SCWCD 5 (94%)
    java.util.function Interfaces Cheat SheetJava Versions Cheat Sheet

  7. #7
    Il file jar avviava soltanto uno dei due vbs e dalla shell mi dava errore , però ho risolto così il problema :

    class Riprovo
    {
    public static void main(String args[])
    {
    try{
    Runtime rt=Runtime.getRuntime();
    Process proc=rt.exec("cmd /c two.vbs");

    }
    catch(Exception e){}
    }
    }

    In pratica il file jar avvia two.vbs , mentre sarà two.vbs a far partire gli altri due !!!!

    Problema risolto !

    Ma grazie al tuo aiuto che per me è stato fondamentale , ti auguro un buon lavoro e una buona giornata

    ciao Andbin


  8. #8
    Utente di HTML.it L'avatar di andbin
    Registrato dal
    Jan 2006
    residenza
    Italy
    Messaggi
    18,284
    Originariamente inviato da Runcommand
    In pratica il file jar avvia two.vbs , mentre sarà two.vbs a far partire gli altri due !!!!
    Ma sinceramente, in linea generale, non vedo problemi nel eseguire 2 exec di seguito!!! Dovrebbe funzionare. A meno che per qualche motivo, il primo è ok mentre il secondo lancia una eccezione (generalmente IOException se non riesce ad avviare il processo). O cose del genere .....
    Questo dovresti verificarlo tu (e non di certo mettendo un catch "vuoto" come invece hai fatto!!!).
    Andrea, andbin.devSenior Java developerSCJP 5 (91%) • SCWCD 5 (94%)
    java.util.function Interfaces Cheat SheetJava Versions Cheat Sheet

  9. #9
    Per ultimi tre esempi che ho postato , non mi crea neppure il class ,
    quindi c'è un errore nella sintassi , non mi da errore invece se faccio così :

    Process proc=rt.exec("cmd /c text.vbs , omega.vbs");

    ma poi si avvia soltanto il primo dei file .......... bo !!!!

    ciao andbin


  10. #10
    Utente di HTML.it L'avatar di andbin
    Registrato dal
    Jan 2006
    residenza
    Italy
    Messaggi
    18,284
    Originariamente inviato da Runcommand
    Per ultimi tre esempi che ho postato , non mi crea neppure il class ,
    quindi c'è un errore nella sintassi
    Sì vero (prima non ci avevo fatto caso ... guardavo più che altro le exec e i comandi).
    Hai dichiarato variabili locali duplicate!!!!

    codice:
    Runtime rt=Runtime.getRuntime();
    Process proc=rt.exec("cmd /c text.vbs");
    Runtime rt=Runtime.getRuntime();
    Process proc=rt.exec("cmd /c omega.vbs");
    È un errore.
    Andrea, andbin.devSenior Java developerSCJP 5 (91%) • SCWCD 5 (94%)
    java.util.function Interfaces Cheat SheetJava Versions Cheat Sheet

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.